"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "utils.c" between
multitail-6.4.2.tgz and multitail-6.5.0.tgz

About: multitail lets you view one or multiple files like the original tail program.

utils.c  (multitail-6.4.2.tgz):utils.c  (multitail-6.5.0.tgz)
skipping to change at line 177 skipping to change at line 177
#ifdef AIX #ifdef AIX
return kill(pid, sigtype); return kill(pid, sigtype);
#else #else
return killpg(pid, sigtype); return killpg(pid, sigtype);
#endif #endif
} }
/** stop_process /** stop_process
* - in: int pid pid of process * - in: int pid pid of process
* - returns: nothing * - returns: nothing
* this function sends a TERM-signal to the given process, sleeps for 1009 micro seconds * this function sends a TERM-signal to the given process, sleeps for 1000 micro seconds
* and then sends a KILL-signal to the given process if it still exists. the TER M signal * and then sends a KILL-signal to the given process if it still exists. the TER M signal
* is send so the process gets the possibility to gracefully exit. if it doesn't * is sent so the process gets the possibility to gracefully exit. if it doesn't
do that do that
* in 100 microseconds, it is terminated * in 1000 microseconds, it is terminated
*/ */
void stop_process(pid_t pid) void stop_process(pid_t pid)
{ {
assert(pid > 1); assert(pid > 1);
#ifndef __APPLE__
if (mykillpg(pid, SIGTERM) == -1) if (mykillpg(pid, SIGTERM) == -1)
{ {
if (errno != ESRCH) if (errno != ESRCH)
error_exit(TRUE, FALSE, "Problem stopping child process w ith PID %d (SIGTERM).\n", pid); error_exit(TRUE, FALSE, "Problem stopping child process w ith PID %d (SIGTERM).\n", pid);
} }
#endif
usleep(1000); usleep(1000);
/* process still exists? */ /* process still exists? */
if (mykillpg(pid, SIGTERM) == 0) if (mykillpg(pid, SIGTERM) == 0)
{ {
/* sleep for a millisecond... */ /* sleep for a millisecond... */
usleep(1000); usleep(1000);
/* ...and then really terminate the process */ /* ...and then really terminate the process */
if (mykillpg(pid, SIGKILL) == -1) if (mykillpg(pid, SIGKILL) == -1)
{ {
#ifdef __APPLE__
/* don't exit if the error is EPERM: macOS doesn't allow
you to kill a process that has been already killed
(i.e. zombies), which is what we did with the second
mykillpg above. */
if (errno != ESRCH && errno != EPERM)
#else
if (errno != ESRCH) if (errno != ESRCH)
#endif
error_exit(TRUE, FALSE, "Problem stopping child p rocess with PID %d (SIGKILL).\n", pid); error_exit(TRUE, FALSE, "Problem stopping child p rocess with PID %d (SIGKILL).\n", pid);
} }
} }
#ifdef __APPLE__
else if (errno != ESRCH && errno != EPERM)
#else
else if (errno != ESRCH) else if (errno != ESRCH)
#endif
{
error_exit(TRUE, FALSE, "Problem stopping child process with PID %d (SIGTERM).\n", pid); error_exit(TRUE, FALSE, "Problem stopping child process with PID %d (SIGTERM).\n", pid);
}
/* wait for the last remainder of the died process to go away, /* wait for the last remainder of the died process to go away,
* otherwhise we'll find zombies on our way * otherwhise we'll find zombies on our way
*/ */
if (waitpid(pid, NULL, WNOHANG | WUNTRACED) == -1) if (waitpid(pid, NULL, WNOHANG | WUNTRACED) == -1)
{ {
if (errno != ECHILD) if (errno != ECHILD)
error_exit(TRUE, FALSE, "waitpid() failed\n"); error_exit(TRUE, FALSE, "waitpid() failed\n");
} }
#ifdef __APPLE__
/* since we ignored the case of a EPERM error above,
check if the process got stopped regardless or
if we actually failed to stop it */
BOOL process_gone = FALSE;
for (int i = 0; i < 10; i++)
{
if (i != 0)
usleep(1000);
if (mykillpg(pid, 0) == -1)
{
if (errno == ESRCH)
{
process_gone = TRUE;
break;
}
}
}
if (!process_gone)
error_exit(TRUE, FALSE, "Could not confirm that child process wit
h PID %d has been stopped.\n", pid);
#endif
} }
/** delete_array /** delete_array
* - in: char **list array of strings to free * - in: char **list array of strings to free
* int n number of strings in this array * int n number of strings in this array
* - returns: nothing * - returns: nothing
* this function frees an array of strings: all strings are freed and * this function frees an array of strings: all strings are freed and
* also the pointer-list itself is freed * also the pointer-list itself is freed
*/ */
void delete_array(char **list, int n) void delete_array(char **list, int n)
skipping to change at line 436 skipping to change at line 475
dummy = max_len - (cutlen + 3); dummy = max_len - (cutlen + 3);
memcpy(&buffer[cutlen + 3], &in[len - dummy], dummy + 1); memcpy(&buffer[cutlen + 3], &in[len - dummy], dummy + 1);
return buffer; return buffer;
} }
double get_ts(void) double get_ts(void)
{ {
struct timeval ts; struct timeval ts;
struct timezone tz;
if (gettimeofday(&ts, &tz) == -1) if (gettimeofday(&ts, NULL) == -1)
error_exit(TRUE, FALSE, "gettimeofday() failed"); error_exit(TRUE, FALSE, "gettimeofday() failed");
return (((double)ts.tv_sec) + ((double)ts.tv_usec)/1000000.0); return (((double)ts.tv_sec) + ((double)ts.tv_usec)/1000000.0);
} }
int match_files(char *search_for, char **path, char ***found, char **isdir) int match_files(char *search_for, char **path, char ***found, char **isdir)
{ {
DIR *dir; DIR *dir;
struct dirent *entry; struct dirent *entry;
char *cur_dir = mymalloc(find_path_max() + 1); char *cur_dir = mymalloc(find_path_max() + 1);
 End of changes. 12 change blocks. 
6 lines changed or deleted 45 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)