|
Packit |
8ea169 |
/*
|
|
Packit |
8ea169 |
Copyright (C) 2009 RedHat inc.
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
This program is free software; you can redistribute it and/or modify
|
|
Packit |
8ea169 |
it under the terms of the GNU General Public License as published by
|
|
Packit |
8ea169 |
the Free Software Foundation; either version 2 of the License, or
|
|
Packit |
8ea169 |
(at your option) any later version.
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
This program is distributed in the hope that it will be useful,
|
|
Packit |
8ea169 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
8ea169 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
8ea169 |
GNU General Public License for more details.
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
You should have received a copy of the GNU General Public License along
|
|
Packit |
8ea169 |
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
Packit |
8ea169 |
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
Packit |
8ea169 |
*/
|
|
Packit |
8ea169 |
#include "libabrt.h"
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
int daemon_is_ok()
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
int fd = open(VAR_RUN"/abrt/abrtd.pid", O_RDONLY);
|
|
Packit |
8ea169 |
if (fd < 0)
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
return 0;
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
char pid[sizeof(pid_t)*3 + 2];
|
|
Packit |
8ea169 |
int len = read(fd, pid, sizeof(pid)-1);
|
|
Packit |
8ea169 |
close(fd);
|
|
Packit |
8ea169 |
if (len <= 0)
|
|
Packit |
8ea169 |
return 0;
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
pid[len] = '\0';
|
|
Packit |
8ea169 |
*strchrnul(pid, '\n') = '\0';
|
|
Packit |
8ea169 |
/* paranoia: only allow non-empty numeric strings */
|
|
Packit |
8ea169 |
unsigned i = 0;
|
|
Packit |
8ea169 |
do
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
if (pid[i] < '0' || pid[i] > '9')
|
|
Packit |
8ea169 |
return 0;
|
|
Packit |
8ea169 |
i++;
|
|
Packit |
8ea169 |
} while (pid[i] != '\0');
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
char path[sizeof("/proc/%s/stat") + sizeof(pid)];
|
|
Packit |
8ea169 |
sprintf(path, "/proc/%s/stat", pid);
|
|
Packit |
8ea169 |
struct stat sb;
|
|
Packit |
8ea169 |
if (stat(path, &sb) == -1)
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
return 0;
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
/* TODO: maybe readlink /proc/PID/exe and check that it is "xxx/abrt"? */
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
return 1;
|
|
Packit |
8ea169 |
}
|