mirror of
https://github.com/troglobit/finit.git
synced 2026-12-04 21:58:19 +00:00
Add reboot/halt/poweroff/suspend commands to Finit API
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
e80edbb401
commit
649a269526
4 files changed
+59
-5
No files matched your search
@@ -182,6 +182,49 @@ static svc_t *do_find_byc(char *buf, size_t len)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int do_reboot(int cmd, char *buf, size_t len)
|
||||||
|
{
|
||||||
|
int rc = 1;
|
||||||
|
|
||||||
|
switch (cmd) {
|
||||||
|
case INIT_CMD_REBOOT:
|
||||||
|
_d("reboot");
|
||||||
|
halt = SHUT_REBOOT;
|
||||||
|
service_runlevel(6);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case INIT_CMD_HALT:
|
||||||
|
_d("halt");
|
||||||
|
halt = SHUT_HALT;
|
||||||
|
service_runlevel(0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case INIT_CMD_POWEROFF:
|
||||||
|
_d("poweroff");
|
||||||
|
halt = SHUT_OFF;
|
||||||
|
service_runlevel(0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case INIT_CMD_SUSPEND:
|
||||||
|
_d("suspend");
|
||||||
|
sync();
|
||||||
|
rc = reboot(RB_SW_SUSPEND);
|
||||||
|
if (rc) {
|
||||||
|
if (errno == EINVAL)
|
||||||
|
snprintf(buf, len, "Kernel does not support suspend.");
|
||||||
|
else
|
||||||
|
snprintf(buf, len, "Failed: %s", strerror(errno));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
rc = 255;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char *event;
|
char *event;
|
||||||
void (*cb)(void);
|
void (*cb)(void);
|
||||||
@@ -302,6 +345,13 @@ static void api_cb(uev_t *w, void *arg, int events)
|
|||||||
rq.sleeptime = prevlevel;
|
rq.sleeptime = prevlevel;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case INIT_CMD_REBOOT:
|
||||||
|
case INIT_CMD_HALT:
|
||||||
|
case INIT_CMD_POWEROFF:
|
||||||
|
case INIT_CMD_SUSPEND:
|
||||||
|
result = do_reboot(rq.cmd, rq.data, sizeof(rq.data));
|
||||||
|
break;
|
||||||
|
|
||||||
case INIT_CMD_ACK:
|
case INIT_CMD_ACK:
|
||||||
_d("Client failed reading ACK");
|
_d("Client failed reading ACK");
|
||||||
goto leave;
|
goto leave;
|
||||||
|
|||||||
@@ -74,6 +74,10 @@
|
|||||||
#define INIT_CMD_UNUSED2 14 /* Unused, was INIT_CMD_QUERY_INETD */
|
#define INIT_CMD_UNUSED2 14 /* Unused, was INIT_CMD_QUERY_INETD */
|
||||||
#define INIT_CMD_UNUSED1 15 /* Unused, was INIT_CMD_EMIT */
|
#define INIT_CMD_UNUSED1 15 /* Unused, was INIT_CMD_EMIT */
|
||||||
#define INIT_CMD_GET_RUNLEVEL 16
|
#define INIT_CMD_GET_RUNLEVEL 16
|
||||||
|
#define INIT_CMD_REBOOT 20
|
||||||
|
#define INIT_CMD_HALT 21
|
||||||
|
#define INIT_CMD_POWEROFF 22
|
||||||
|
#define INIT_CMD_SUSPEND 23
|
||||||
#define INIT_CMD_WDOG_HELLO 128 /* Watchdog register and hello */
|
#define INIT_CMD_WDOG_HELLO 128 /* Watchdog register and hello */
|
||||||
#define INIT_CMD_SVC_ITER 129
|
#define INIT_CMD_SVC_ITER 129
|
||||||
#define INIT_CMD_SVC_QUERY 130
|
#define INIT_CMD_SVC_QUERY 130
|
||||||
|
|||||||
@@ -27,13 +27,8 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/reboot.h>
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
#ifndef RB_SW_SUSPEND /* Since Linux 2.5.18, but not in GLIBC until 2.19 */
|
|
||||||
#define RB_SW_SUSPEND 0xd000fce2
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
CMD_UNKNOWN = -1,
|
CMD_UNKNOWN = -1,
|
||||||
CMD_REBOOT = 0,
|
CMD_REBOOT = 0,
|
||||||
|
|||||||
@@ -28,9 +28,14 @@
|
|||||||
#ifdef HAVE_TERMIOS_H /* for screen_width() */
|
#ifdef HAVE_TERMIOS_H /* for screen_width() */
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <sys/reboot.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef RB_SW_SUSPEND /* Since Linux 2.5.18, but not in GLIBC until 2.19 */
|
||||||
|
#define RB_SW_SUSPEND 0xd000fce2
|
||||||
|
#endif
|
||||||
|
|
||||||
extern int screen_rows;
|
extern int screen_rows;
|
||||||
extern int screen_cols;
|
extern int screen_cols;
|
||||||
extern char *prognm;
|
extern char *prognm;
|
||||||
|
|||||||
Reference in new issue
Block a user