1
/* $Id: main.c 4565 2004-05-20 20:45:28Z benny $ */
3
* Copyright (c) 2003-2004 Benedikt Meurer <benny@xfce.org>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2, or (at your option)
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21
* XXX - since this program is executed with root permissions, it may not
22
* be a good idea to trust glib!!
29
#ifdef HAVE_SYS_WAIT_H
60
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
61
#define POWEROFF_CMD "/sbin/shutdown -p now"
62
#define REBOOT_CMD "/sbin/shutdown -r now"
64
#define POWEROFF_CMD "/sbin/shutdown -h now"
65
#define REBOOT_CMD "/sbin/shutdown -r now"
70
run (const gchar *command)
72
#if defined(HAVE_SIGPROCMASK)
82
#if defined(HAVE_SETSID)
86
#if defined (HAVE_SIGPROCMASK)
87
sigemptyset (&sigset);
88
sigaddset (&sigset, SIGHUP);
89
sigaddset (&sigset, SIGINT);
90
sigprocmask (SIG_BLOCK, &sigset, NULL);
93
result = g_shell_parse_argv (command, &argc, &argv, &err);
97
envp = g_new0 (gchar *, 1);
99
result = g_spawn_sync (NULL, argv, envp,
100
G_SPAWN_SEARCH_PATH | G_SPAWN_STDOUT_TO_DEV_NULL |
101
G_SPAWN_STDERR_TO_DEV_NULL,
102
NULL, NULL, NULL, NULL, &status, &err);
114
return (WIFEXITED (status) && WEXITSTATUS (status) == 0);
119
main (int argc, char **argv)
121
gboolean succeed = FALSE;
125
fprintf (stdout, "XFSM_SUDO_DONE ");
128
if (fgets (action, 1024, stdin) == NULL)
130
fprintf (stdout, "FAILED\n");
134
if (strncasecmp (action, "POWEROFF", 8) == 0)
136
succeed = run (POWEROFF_CMD);
138
else if (strncasecmp (action, "REBOOT", 6) == 0)
140
succeed = run (REBOOT_CMD);
145
fprintf (stdout, "SUCCEED\n");
149
fprintf (stdout, "FAILED\n");