# # # patch "ChangeLog" # from [3d154730aed26a1d89a159e3cfb6370955505d85] # to [9da00a4695628a576e96261da856cb7dd73e401c] # # patch "unix/process.cc" # from [cf599e8f9f8dd9865bd7e867eefa3ed3b8f57998] # to [6d5a714d0d0c8d260b2708ac9ad548864b58a3a5] # ============================================================ --- ChangeLog 3d154730aed26a1d89a159e3cfb6370955505d85 +++ ChangeLog 9da00a4695628a576e96261da856cb7dd73e401c @@ -1,3 +1,9 @@ +2006-12-26 Derek Scherger + + * unix/process.cc (is_executable, make_executable, process_spawn, + process_spawn, redir, process_wait, process_kill, process_sleep, + get_process_id): fix indentation + 2006-12-26 Matthew Gregan * Makefile.am (BOTAN_SOURCES): Remove entries for missing headers, ============================================================ --- unix/process.cc cf599e8f9f8dd9865bd7e867eefa3ed3b8f57998 +++ unix/process.cc 6d5a714d0d0c8d260b2708ac9ad548864b58a3a5 @@ -47,12 +47,12 @@ bool is_executable(const char *path) bool is_executable(const char *path) { - struct stat s; + struct stat s; - int rc = stat(path, &s); - N(rc != -1, F("error getting status of file %s: %s") % path % os_strerror(errno)); + int rc = stat(path, &s); + N(rc != -1, F("error getting status of file %s: %s") % path % os_strerror(errno)); - return (s.st_mode & S_IXUSR) && !(s.st_mode & S_IFDIR); + return (s.st_mode & S_IXUSR) && !(s.st_mode & S_IFDIR); } // copied from libc info page @@ -66,43 +66,43 @@ int make_executable(const char *path) int make_executable(const char *path) { - mode_t mode; - struct stat s; - int fd = open(path, O_RDONLY); - N(fd != -1, F("error opening file %s: %s") % path % os_strerror(errno)); - if (fstat(fd, &s)) - return -1; - mode = s.st_mode; - mode |= ((S_IXUSR|S_IXGRP|S_IXOTH) & ~read_umask()); - int ret = fchmod(fd, mode); - N(close(fd) == 0, F("error closing file %s: %s") % path % os_strerror(errno)); - return ret; + mode_t mode; + struct stat s; + int fd = open(path, O_RDONLY); + N(fd != -1, F("error opening file %s: %s") % path % os_strerror(errno)); + if (fstat(fd, &s)) + return -1; + mode = s.st_mode; + mode |= ((S_IXUSR|S_IXGRP|S_IXOTH) & ~read_umask()); + int ret = fchmod(fd, mode); + N(close(fd) == 0, F("error closing file %s: %s") % path % os_strerror(errno)); + return ret; } pid_t process_spawn(const char * const argv[]) { - { - std::ostringstream cmdline_ss; - for (const char *const *i = argv; *i; ++i) - { - if (i != argv) - cmdline_ss << ", "; - cmdline_ss << "'" << *i << "'"; - } - L(FL("spawning command: %s\n") % cmdline_ss.str()); - } - pid_t pid; - pid = fork(); - switch (pid) - { - case -1: /* Error */ - return -1; - case 0: /* Child */ - execvp(argv[0], (char * const *)argv); - raise(SIGKILL); - default: /* Parent */ - return pid; - } + { + std::ostringstream cmdline_ss; + for (const char *const *i = argv; *i; ++i) + { + if (i != argv) + cmdline_ss << ", "; + cmdline_ss << "'" << *i << "'"; + } + L(FL("spawning command: %s\n") % cmdline_ss.str()); + } + pid_t pid; + pid = fork(); + switch (pid) + { + case -1: /* Error */ + return -1; + case 0: /* Child */ + execvp(argv[0], (char * const *)argv); + raise(SIGKILL); + default: /* Parent */ + return pid; + } } struct redir @@ -114,7 +114,7 @@ redir::redir(int which, char const * fil ~redir(); }; redir::redir(int which, char const * file) - : savedfd(-1), fd(which) + : savedfd(-1), fd(which) { if (!file || *file == '\0') return; @@ -165,41 +165,41 @@ int process_wait(pid_t pid, int *res, in int process_wait(pid_t pid, int *res, int timeout) { - int status; - int flags = 0; - if (timeout == -1) - timeout = 0; - else - flags |= WNOHANG; - int r; - for (r = 0; r == 0 && timeout >= 0; --timeout) - { - r = waitpid(pid, &status, flags); - if (r == 0 && timeout > 0) - process_sleep(1); - } - if (r == 0) - return -1; - if (WIFEXITED(status)) - *res = WEXITSTATUS(status); - else - *res = -WTERMSIG(status); - return 0; + int status; + int flags = 0; + if (timeout == -1) + timeout = 0; + else + flags |= WNOHANG; + int r; + for (r = 0; r == 0 && timeout >= 0; --timeout) + { + r = waitpid(pid, &status, flags); + if (r == 0 && timeout > 0) + process_sleep(1); + } + if (r == 0) + return -1; + if (WIFEXITED(status)) + *res = WEXITSTATUS(status); + else + *res = -WTERMSIG(status); + return 0; } int process_kill(pid_t pid, int signal) { - return kill(pid, signal); + return kill(pid, signal); } int process_sleep(unsigned int seconds) { - return sleep(seconds); + return sleep(seconds); } pid_t get_process_id() { - return getpid(); + return getpid(); } void ignore_sigpipe()