summaryrefslogtreecommitdiff
path: root/src/state/s6-linux-init-telinit.c
blob: 856e78ba932936e59e0cd13cb381e6f6f414dda3 (plain)
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
/* ISC license. */

#include <skalibs/sgetopt.h>
#include <skalibs/types.h>
#include <skalibs/strerr2.h>

#include "defaults.h"
#include "initctl.h"
#include "hpr.h"

#define USAGE "s6-linux-init-telinit runlevel"
#define dieusage() strerr_dieusage(100, USAGE)

int main (int argc, char const *const *argv, char const *const *envp)
{
  PROG = "s6-linux-init-telinit" ;
  {
    subgetopt_t l = SUBGETOPT_ZERO ;
    for (;;)
    {
      int opt = subgetopt_r(argc, argv, "rc:p:s:m:d:", &l) ;
      if (opt == -1) break ;
      switch (opt)
      {
        case 'r' :
        case 'c' :
        case 'p' :
        case 's' :
        case 'm' :
        case 'd' : break ;
        default : dieusage() ;
      }
    }
    argc -= l.ind ; argv += l.ind ;
  }

  if (!argc) dieusage() ;
  if (!argv[0][0] || argv[0][1]) dieusage() ;
  if (argv[0][0] != 'S' && (argv[0][0] < '0' || argv[0][0] > '6')) dieusage() ;
  if (!hpr_send(argv[0], 1)) strerr_diefu2sys(111, "write to ", INITCTL) ;
  return 0 ;
}