Print this page
10075 make usr/src/tools smatch clean
   1 /*
   2  * This file and its contents are supplied under the terms of the
   3  * Common Development and Distribution License ("CDDL"), version 1.0.
   4  * You may only use this file in accordance with the terms of version
   5  * 1.0 of the CDDL.
   6  *
   7  * A full copy of the text of the CDDL should have accompanied this
   8  * source.  A copy of the CDDL is also available via the Internet at
   9  * http://www.illumos.org/license/CDDL.
  10  */
  11 
  12 /*
  13  * Copyright 2011 Jason King.  All rights reserved.

  14  */
  15 
  16 #include <stdlib.h>
  17 #include <stdio.h>
  18 #include <string.h>
  19 #include <unistd.h>
  20 #include <sys/types.h>
  21 #include <sys/stat.h>
  22 #include <sys/wait.h>
  23 #include <fcntl.h>
  24 #include <err.h>
  25 #include <spawn.h>
  26 
  27 #define MCS     "/usr/bin/mcs"
  28 
  29 #define ELFLEN 4
  30 static const char elf_signature[] = "\177ELF";
  31 static posix_spawnattr_t attr;
  32 static const char *cmd[] = { MCS, "-d", "-n", ".SUNW_ctf", NULL, NULL };
  33 


 115 fix_file(const char *filename, mode_t mode)
 116 {
 117         pid_t pid;
 118         int i, rc;
 119         int stat = 0;
 120 
 121         if ((mode & S_IWUSR) == 0) {
 122                 if (chmod(filename, mode | S_IWUSR) == -1) {
 123                         warn("failed to make %s writable", filename);
 124                         return (B_FALSE);
 125                 }
 126         }
 127 
 128         cmd[4] = filename;
 129         if ((rc = posix_spawn(&pid, MCS, NULL, &attr,
 130             (char *const *)cmd, environ)) != 0) {
 131                 warnx("could not exec mcs: %s", strerror(rc));
 132                 return (B_FALSE);
 133         }
 134 
 135         waitpid(pid, &stat, 0);
 136         if (!WIFEXITED(stat) || WEXITSTATUS(stat) != 0) {
 137                 warnx("Removing CTF information from %s failed", filename);
 138                 return (B_FALSE);
 139         }
 140 
 141         if ((mode & S_IWUSR) == 0) {
 142                 if (chmod(filename, mode) == -1) {
 143                         warn("could not reset permissions of %s", filename);
 144                         return (B_FALSE);
 145                 }
 146         }
 147 
 148         return (B_TRUE);
 149 }
 150 
 151 static void
 152 usage(const char *name)
 153 {
 154         (void) fprintf(stderr, "Usage: %s file...\n", name);
 155         exit(EXIT_FAILURE);
   1 /*
   2  * This file and its contents are supplied under the terms of the
   3  * Common Development and Distribution License ("CDDL"), version 1.0.
   4  * You may only use this file in accordance with the terms of version
   5  * 1.0 of the CDDL.
   6  *
   7  * A full copy of the text of the CDDL should have accompanied this
   8  * source.  A copy of the CDDL is also available via the Internet at
   9  * http://www.illumos.org/license/CDDL.
  10  */
  11 
  12 /*
  13  * Copyright 2011 Jason King.  All rights reserved.
  14  * Copyright (c) 2018, Joyent, Inc.
  15  */
  16 
  17 #include <stdlib.h>
  18 #include <stdio.h>
  19 #include <string.h>
  20 #include <unistd.h>
  21 #include <sys/types.h>
  22 #include <sys/stat.h>
  23 #include <sys/wait.h>
  24 #include <fcntl.h>
  25 #include <err.h>
  26 #include <spawn.h>
  27 
  28 #define MCS     "/usr/bin/mcs"
  29 
  30 #define ELFLEN 4
  31 static const char elf_signature[] = "\177ELF";
  32 static posix_spawnattr_t attr;
  33 static const char *cmd[] = { MCS, "-d", "-n", ".SUNW_ctf", NULL, NULL };
  34 


 116 fix_file(const char *filename, mode_t mode)
 117 {
 118         pid_t pid;
 119         int i, rc;
 120         int stat = 0;
 121 
 122         if ((mode & S_IWUSR) == 0) {
 123                 if (chmod(filename, mode | S_IWUSR) == -1) {
 124                         warn("failed to make %s writable", filename);
 125                         return (B_FALSE);
 126                 }
 127         }
 128 
 129         cmd[4] = filename;
 130         if ((rc = posix_spawn(&pid, MCS, NULL, &attr,
 131             (char *const *)cmd, environ)) != 0) {
 132                 warnx("could not exec mcs: %s", strerror(rc));
 133                 return (B_FALSE);
 134         }
 135 
 136         (void) waitpid(pid, &stat, 0);
 137         if (!WIFEXITED(stat) || WEXITSTATUS(stat) != 0) {
 138                 warnx("Removing CTF information from %s failed", filename);
 139                 return (B_FALSE);
 140         }
 141 
 142         if ((mode & S_IWUSR) == 0) {
 143                 if (chmod(filename, mode) == -1) {
 144                         warn("could not reset permissions of %s", filename);
 145                         return (B_FALSE);
 146                 }
 147         }
 148 
 149         return (B_TRUE);
 150 }
 151 
 152 static void
 153 usage(const char *name)
 154 {
 155         (void) fprintf(stderr, "Usage: %s file...\n", name);
 156         exit(EXIT_FAILURE);