3 // Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
4 // based on vreboot.cc by Jacques Gelinas
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 02111-1307, USA.
21 Used to send a reboot message to the reboot manager. It opens /dev/reboot
31 #include <sys/types.h>
35 #include <sys/socket.h>
40 Connect to a unix domain socket
42 static int vreboot_connect (const char *sockpath, bool showerror)
45 int fd = socket (AF_UNIX,SOCK_STREAM,0);
47 if (showerror) perror("socket client");
49 struct sockaddr_un un;
52 un.sun_family = AF_UNIX;
53 strcpy (un.sun_path,sockpath);
54 s = connect(fd,(struct sockaddr*)&un,sizeof(un));
56 if (showerror) fprintf (stderr,"connect %s (%s)\n"
57 ,sockpath,strerror(errno));
67 fprintf (stderr,"vreboot version %s\n",VERSION);
68 fprintf (stderr,"\n");
69 fprintf (stderr,"vreboot [ --socket path ]\n");
70 fprintf (stderr,"vhalt [ --socket path ]\n");
71 fprintf (stderr,"vreboot request a reboot or a halt of a virtual server\n");
74 int main (int argc, char *argv[])
78 const char *sockpath = "/dev/reboot";
79 for (i=1; i<argc; i++){
80 const char *arg = argv[i];
81 const char *opt = argv[i+1];
82 if (strcmp(arg,"--socket")==0){
85 }else if (strcmp(arg,"--help")==0){
89 fprintf (stderr,"Invalid option %s\n",arg);
96 int fd = vreboot_connect (sockpath,true);
98 if (strstr(argv[0],"halt")!=NULL){
99 write (fd,"halt\n",5);
101 write (fd,"reboot\n",7);