mirror of
https://github.com/troglobit/libite.git
synced 2026-11-08 16:11:05 +00:00
Add generic support for running tests as root.
By setting `ASROOT=1` in a unit test makefile a test will now run as root, using `sudo -n`. This patch allows us to simplify the pidfilefn() test. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
e8ff38ad6a
commit
44e787c966
3 files changed
+22
-7
No files matched your search
+10
-3
@@ -120,7 +120,11 @@ int pidfile_signal(const char *pidfile, int signal)
|
||||
|
||||
/********************************* UNIT TESTS ************************************/
|
||||
#ifdef UNITTEST
|
||||
#define PIDFILE "/tmp/pidfilefn.test.pid"
|
||||
#include <paths.h>
|
||||
#include "lite.h"
|
||||
|
||||
extern char *__progname;
|
||||
static char PIDFILE[42];
|
||||
|
||||
static void sigterm_handler(int signo)
|
||||
{
|
||||
@@ -131,10 +135,15 @@ static void sigalrm_handler(int signo)
|
||||
{
|
||||
printf("Testing pidfile() ...\n");
|
||||
pidfile(NULL);
|
||||
|
||||
if (!fexist(PIDFILE))
|
||||
err(1, "pidfile() failed creating %s", PIDFILE);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
snprintf(PIDFILE, sizeof(PIDFILE), "%s%s.pid", _PATH_VARRUN, __progname);
|
||||
|
||||
signal(SIGTERM, sigterm_handler);
|
||||
signal(SIGALRM, sigalrm_handler);
|
||||
alarm(1);
|
||||
@@ -145,8 +154,6 @@ int main(void)
|
||||
else
|
||||
printf("We got signal!\n");
|
||||
|
||||
system("ls -ld " PIDFILE);
|
||||
|
||||
printf("Reading pid file, should be %d ...\n", getpid());
|
||||
printf("=> %d\n", pidfile_read(PIDFILE));
|
||||
|
||||
|
||||
Reference in new issue
Block a user