/* Copyright Jacques Gelinas jack@solucorp.qc.ca Distributed under the Gnu Public License, see the License file in this package. */ /* Used to send a reboot message to the reboot manager. It opens /dev/reboot and write "reboot\n". */ #include #include #include #include #include #include #include #include #include /* Connect to a unix domain socket */ static int vreboot_connect (const char *sockpath, bool showerror) { int ret = -1; int fd = socket (AF_UNIX,SOCK_STREAM,0); if (fd == -1){ if (showerror) perror("socket client"); }else{ struct sockaddr_un un; un.sun_family = AF_UNIX; strcpy (un.sun_path,sockpath); int s = connect(fd,(struct sockaddr*)&un,sizeof(un)); if (s == -1){ if (showerror) fprintf (stderr,"connect %s (%s)\n" ,sockpath,strerror(errno)); }else{ ret = fd; } } return ret; } static void usage() { fprintf (stderr,"vreboot version %s\n",VERSION); fprintf (stderr,"\n"); fprintf (stderr,"vreboot [ --socket path ]\n"); fprintf (stderr,"vhalt [ --socket path ]\n"); fprintf (stderr,"vreboot request a reboot or a halt of a virtual server\n"); } int main (int argc, char *argv[]) { int ret = -1; int i; const char *sockpath = "/dev/reboot"; for (i=1; i