-
Notifications
You must be signed in to change notification settings - Fork 8
/
hda-ctl-hup.c
57 lines (44 loc) · 1.33 KB
/
hda-ctl-hup.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Amahi Home Server
// Copyright (C) 2007-2009 Amahi Team
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License v3
// (29 June 2007), as published in the COPYING file.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// file COPYING for more details.
//
// You should have received a copy of the GNU General Public
// License along with this program; if not, write to the Amahi
// team at http://www.amahi.org/ under "Contact Us."
/* signal the hda-ctl process */
/* exits with 0 if it works, -1 if not */
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <signal.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#define SZ 20
int main (int argc, char *argv[])
{
int fd = open ("/var/run/hda-ctl.pid", O_RDONLY);
if (fd < 0) exit (-1);
char buf[SZ];
int rd = read(fd, &buf, SZ-1);
if (rd < 1) exit (-1);
buf[SZ-1]='\0';
int pid = strtol(buf, NULL, 10);
int ret = 0;
if (argc > 1 && !strncmp(argv[1], "usr1", 4)) {
ret = kill(pid, SIGUSR1);
} else {
ret = kill(pid, SIGHUP);
printf("Your HDA services have been restarted.\n");
}
return ret;
}