]> arthur.barton.de Git - netatalk.git/blobdiff - etc/atalkd/main.c
remove or mark as ok more gcc warnings.
[netatalk.git] / etc / atalkd / main.c
index 3106c04244c0c55619dccc909fe2231732eed243..f43fb5e55359f5e53dc3a8640323964c417fe69c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: main.c,v 1.17.8.1 2004-01-10 08:09:12 bfernhomberg Exp $
+ * $Id: main.c,v 1.17.8.6.2.1 2005-01-31 17:01:04 didg Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved. See COPYRIGHT.
@@ -156,6 +156,10 @@ static void atalkd_exit(const int i)
              ntohs(iface->i_addr.sat_addr.s_net), 
              iface->i_addr.sat_addr.s_node, strerror(errno));
     }
+#ifdef linux
+    if (!(iface->i_flags & IFACE_WASALLMULTI) && (iface->i_flags & IFACE_ALLMULTI))
+        ifsetallmulti(iface->i_name, 0);
+#endif /* linux */
   }
 #endif /* SOPCDOFADDR */
 
@@ -691,7 +695,7 @@ consistency()
        for ( lr = zt->zt_rt; lr; lr = lr->l_next ) {
            rtmp = (struct rtmptab *)lr->l_data;
            if ( rtmp->rt_iprev == 0 && rtmp->rt_gate != 0 ) {
-               LOG(log_error, logtype_atalkd, "%.*s has %u-%u (unused)\n",
+               LOG(log_error, logtype_atalkd, "%.*s has %u-%u (unused)",
                        zt->zt_len, zt->zt_name, ntohs( rtmp->rt_firstnet ),
                        ntohs( rtmp->rt_lastnet ));
                atalkd_exit(1);
@@ -702,7 +706,7 @@ consistency()
                }
            }
            if ( lz == 0 ) {
-               LOG(log_error, logtype_atalkd, "no map from %u-%u to %.*s\n", 
+               LOG(log_error, logtype_atalkd, "no map from %u-%u to %.*s", 
                        ntohs( rtmp->rt_firstnet ),
                        ntohs( rtmp->rt_lastnet ),
                        zt->zt_len, zt->zt_name );
@@ -863,14 +867,15 @@ int main( ac, av )
     struct sockaddr_at sat;
     struct sigaction   sv;
     struct itimerval   it;
+    sigset_t            signal_set, old_set;
+    
     struct interface   *iface;
     int                        status;
     struct atport      *ap;
     fd_set             readfds;
-    int                        i, mask, c;
+    int                        i, c;
     SOCKLEN_T          fromlen;
     char               *prog;
-;
 
     while (( c = getopt( ac, av, "12qsdtf:P:v" )) != EOF ) {
        switch ( c ) {
@@ -1025,6 +1030,12 @@ int main( ac, av )
        exit( 1 );
     }
 
+    /*
+     * Set process name for logging
+     */
+
+    set_processname("atalkd");
+
     /* do this here so that we can use ifconfig */
 #ifdef __svr4__
     if ( plumb() < 0 ) {
@@ -1157,6 +1168,14 @@ int main( ac, av )
        atalkd_exit( 1 );
     }
 
+    sigemptyset( &signal_set );
+    sigaddset(&signal_set, SIGALRM);
+#if 0
+    /* don't block SIGTERM */
+    sigaddset(&signal_set, SIGTERM);
+#endif
+    sigaddset(&signal_set, SIGUSR1);
+
     for (;;) {
        readfds = fds;
        if ( select( nfds, &readfds, NULL, NULL, NULL) < 0 ) {
@@ -1179,7 +1198,7 @@ int main( ac, av )
                            LOG(log_error, logtype_atalkd, "recvfrom: %s", strerror(errno) );
                            continue;
                        }
-#ifdef DEBUG
+#ifdef DEBUG1
                        if ( debug ) {
                            printf( "packet from %u.%u on %s (%x) %d (%d)\n",
                                    ntohs( sat.sat_addr.s_net ),
@@ -1187,16 +1206,12 @@ int main( ac, av )
                                    iface->i_flags, ap->ap_port, ap->ap_fd );
                            bprint( Packet, c );
                        }
-#endif /* DEBUG */
-#ifdef __svr4__
-                       if ( sighold( SIGALRM ) || sighold( SIGUSR1 )) {
-                           LOG(log_error, logtype_atalkd, "sighold: %s", strerror(errno) );
+#endif 
+                       if (sigprocmask(SIG_BLOCK, &signal_set, &old_set) < 0) {
+                           LOG(log_error, logtype_atalkd, "sigprocmask: %s", strerror(errno) );
                            atalkd_exit( 1 );
                        }
-#else /* __svr4__ */
-                       mask = sigsetmask( sigmask( SIGALRM ) |
-                               sigmask( SIGUSR1 ));
-#endif /* __svr4__ */
+
                        if (( *ap->ap_packet )( ap, &sat, Packet, c ) < 0) {
                          LOG(log_error, logtype_atalkd, "ap->ap_packet: %s", strerror(errno));
                          atalkd_exit(1);
@@ -1204,15 +1219,12 @@ int main( ac, av )
 
 #ifdef DEBUG
                        consistency();
-#endif /* DEBUG */
-#ifdef __svr4__
-                       if ( sigrelse( SIGUSR1 ) || sigrelse( SIGALRM )) {
-                           LOG(log_error, logtype_atalkd, "sigrelse: %s", strerror(errno) );
+#endif 
+                       if (sigprocmask(SIG_SETMASK, &old_set, NULL) < 0) {
+                           LOG(log_error, logtype_atalkd, "sigprocmask old set: %s", strerror(errno) );
                            atalkd_exit( 1 );
                        }
-#else /* __svr4__ */
-                       sigsetmask( mask );
-#endif /* __svr4__ */
+
                    }
                }
            }
@@ -1342,7 +1354,8 @@ smaller net range.", iface->i_name, ntohs(first), ntohs(last), strerror(errno));
 
     /* open ports */
     i = 1; /* enable broadcasts */
-#ifdef __svr4__ 
+#if 0
+    /* useless message, no? */
     LOG(log_info, logtype_atalkd, "setsockopt incompatible w/ Solaris STREAMS module.");
 #endif /* __svr4__ */
     for ( ap = iface->i_ports; ap; ap = ap->ap_next ) {
@@ -1397,6 +1410,43 @@ smaller net range.", iface->i_name, ntohs(first), ntohs(last), strerror(errno));
     nfds++;
 }
 
+int ifsetallmulti ( iname, set )
+const char             *iname;
+int set;
+{
+    int sock;
+    struct ifreq ifr;
+
+    memset(&ifr, 0, sizeof(ifr));
+
+    if (( sock = socket( AF_APPLETALK, SOCK_DGRAM, 0 )) < 0 ) {
+        return( -1 );
+    }
+
+    /* get interface config */
+    strlcpy(ifr.ifr_name, iname, sizeof(ifr.ifr_name));
+    if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0) {
+        close(sock);
+        return (-1);
+    }
+
+    /* should we set or unset IFF_ALLMULTI */
+    if (set)
+           ifr.ifr_flags |= IFF_ALLMULTI;
+    else
+           ifr.ifr_flags &= ~IFF_ALLMULTI;
+
+    /* set interface config */
+    strlcpy(ifr.ifr_name, iname, sizeof(ifr.ifr_name));
+    if (ioctl(sock, SIOCSIFFLAGS, &ifr) < 0) {
+        close(sock);   
+        return -1;
+    }
+
+    close(sock);
+    return (0);
+}
+
 int ifconfig( iname, cmd, sa )
     const char         *iname;
     unsigned long      cmd;