@@ -512,10 +512,11 @@ get_fifo_path() {
512512
513513static int
514514get_fifo_path (char *buf, size_t bufsize) {
515+ int len;
515516 const char *s = get_fifo_path ();
516517 if (!s) return -1 ;
517- snprintf (buf, bufsize, " %s" , s);
518- return 0 ;
518+ len= snprintf (buf+ 1 , bufsize- 1 , " %s" , s);
519+ return len ;
519520}
520521
521522int main (int argc, char **argv) {
@@ -548,37 +549,40 @@ int main(int argc, char **argv) {
548549 for (int i=1 ; i<argc; i++) { args.push_back (string (argv[i])); }
549550
550551become_master:
552+ int len=0 ;
551553 int fd = socket (PF_UNIX, SOCK_STREAM, 0 );
552554 if (fd == -1 ) { perror (" socket" ); exit (1 ); }
553555
554556 int enable = 1 ;
555557 setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof (enable));
556558 struct sockaddr_un addr;
559+ memset (&addr, 0x0 , sizeof (addr));
557560 addr.sun_family = AF_UNIX;
558- if (get_fifo_path (addr.sun_path , sizeof (addr.sun_path )) < 0 )
561+ if ((len= get_fifo_path (addr.sun_path , sizeof (addr.sun_path ) )) < 0 )
559562 exit (1 );
560- int result = ::bind (fd, (sockaddr*)&addr, sizeof (addr));
563+
564+ // plus one because we use the abstract namespace, it will show up in
565+ // /proc/net/unix prefixed with an @
566+ int result = ::bind (fd, (sockaddr*)&addr, len+sizeof (addr.sun_family )+1 );
561567
562568 if (result == 0 ) {
563569 int result = listen (fd, 10 );
564570 if (result != 0 ) { perror (" listen" ); exit (1 ); }
565571 setsid (); // create a new session if we can...
566572 result = master (fd, args);
567- unlink (get_fifo_path ());
568573 return result;
569574 } else if (errno == EADDRINUSE) {
570575 struct timeval t0, t1;
571576 gettimeofday (&t0, NULL );
572577 gettimeofday (&t1, NULL );
573578 for (int i=0 ; i < 3 || (t1.tv_sec < 3 + t0.tv_sec ) ; i++) {
574- result = connect (fd, (sockaddr*)&addr, sizeof (addr) );
579+ result = connect (fd, (sockaddr*)&addr, len+ sizeof (addr. sun_family )+ 1 );
575580 if (result == 0 ) break ;
576581 if (i==0 ) srand48 (t0.tv_sec ^ t0.tv_usec );
577582 usleep (lrand48 () % 100000 );
578583 gettimeofday (&t1, NULL );
579584 }
580585 if (result < 0 && errno == ECONNREFUSED) {
581- unlink (get_fifo_path ());
582586 fprintf (stderr, " Waited 3 seconds for master. giving up.\n " );
583587 close (fd);
584588 goto become_master;
0 commit comments