#include #include #include #include #include #include #include #include static int unix_connect(const char *sockn) { int ret = -1; int fd = socket (AF_UNIX,SOCK_STREAM,0); if (fd == -1){ fprintf (stderr,"Can't create socket (%s)\n",strerror(errno)); }else{ struct sockaddr_un un; un.sun_family = AF_UNIX; strcpy (un.sun_path,sockn); int s = connect(fd,(struct sockaddr*)&un,sizeof(un)); if (s == -1){ fprintf (stderr,"Can't connect (%s)\n",strerror(errno)); close (fd); }else{ ret = fd; } } return ret; } int main (int argc, char *argv[]) { if (argc != 3){ fprintf (stderr,"vservertalk %s\n" "Sends a message to a running vserver.\n" "Talks to the init process.\n" "\n" "vservertalk unix_socket message\n" ,VERSION); }else{ int fd = unix_connect (argv[1]); if (fd != -1){ write (fd,argv[2],strlen(argv[2])); } } return 0; }