kill_all: create strings with xasprintf
This commit is contained in:
parent
0110487722
commit
74cfb455c5
@ -87,10 +87,11 @@ static int mount_proc(void)
|
|||||||
|
|
||||||
static bool is_user_process(pid_t pid)
|
static bool is_user_process(pid_t pid)
|
||||||
{
|
{
|
||||||
char buf[PATH_MAX+1];
|
char *buf = NULL;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char path[PATH_MAX+1];
|
char *path = NULL;
|
||||||
pid_t temp_pid;
|
pid_t temp_pid;
|
||||||
|
size_t size;
|
||||||
bool user_process = true;
|
bool user_process = true;
|
||||||
|
|
||||||
while (pid >0 && user_process) {
|
while (pid >0 && user_process) {
|
||||||
@ -98,8 +99,9 @@ static bool is_user_process(pid_t pid)
|
|||||||
user_process = false;
|
user_process = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
snprintf(path, sizeof(path), "/proc/%d/status", pid);
|
xasprintf(&path, "/proc/%d/status", pid);
|
||||||
fp = fopen(path, "r");
|
fp = fopen(path, "r");
|
||||||
|
free(path);
|
||||||
/*
|
/*
|
||||||
* if we could not open the file, the process disappeared, which
|
* if we could not open the file, the process disappeared, which
|
||||||
* leaves us no way to determine for sure whether it was a user
|
* leaves us no way to determine for sure whether it was a user
|
||||||
@ -112,11 +114,14 @@ static bool is_user_process(pid_t pid)
|
|||||||
}
|
}
|
||||||
temp_pid = -1;
|
temp_pid = -1;
|
||||||
while (! feof(fp)) {
|
while (! feof(fp)) {
|
||||||
buf[0] = 0;
|
buf = NULL;
|
||||||
if (fgets(buf, sizeof(buf), fp))
|
if (getline(&buf, &size, fp) != -1) {
|
||||||
sscanf(buf, "PPid: %d", &temp_pid);
|
sscanf(buf, "PPid: %d", &temp_pid);
|
||||||
else
|
free(buf);
|
||||||
|
} else {
|
||||||
|
free(buf);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
if (temp_pid == -1) {
|
if (temp_pid == -1) {
|
||||||
@ -135,7 +140,7 @@ static int signal_processes(int sig, RC_STRINGLIST *omits, bool dryrun)
|
|||||||
sigset_t oldsigs;
|
sigset_t oldsigs;
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
struct dirent *d;
|
struct dirent *d;
|
||||||
char buf[PATH_MAX+1];
|
char *buf = NULL;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
int sendcount = 0;
|
int sendcount = 0;
|
||||||
|
|
||||||
@ -170,7 +175,11 @@ static int signal_processes(int sig, RC_STRINGLIST *omits, bool dryrun)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* Is this a process we have been requested to omit? */
|
/* Is this a process we have been requested to omit? */
|
||||||
sprintf(buf, "%d", pid);
|
if (buf) {
|
||||||
|
free(buf);
|
||||||
|
buf = NULL;
|
||||||
|
}
|
||||||
|
xasprintf(&buf, "%d", pid);
|
||||||
if (rc_stringlist_find(omits, buf))
|
if (rc_stringlist_find(omits, buf))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user