libbb,crond,lash: fix getopt32 (don't know how it managed to slip through)
[oweals/busybox.git] / include / libbb.h
index 6c6bec71ebd7b7660c74a3602a0a47720db78eef..e514fe2f2deb5a44cf01322a5d2672815dacb8da 100644 (file)
@@ -26,7 +26,7 @@
 #include <stdarg.h>
 #include <stddef.h>
 #include <string.h>
-#include <strings.h>
+/* #include <strings.h> - said to be obsolete */
 #include <sys/ioctl.h>
 #include <sys/mman.h>
 #include <sys/socket.h>
@@ -241,6 +241,7 @@ extern char *bb_get_last_path_component(char *path);
 
 int ndelay_on(int fd);
 int ndelay_off(int fd);
+void xdup2(int, int);
 void xmove_fd(int, int);
 
 
@@ -282,7 +283,13 @@ void xlisten(int s, int backlog);
 void xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen);
 ssize_t xsendto(int s, const void *buf, size_t len, const struct sockaddr *to,
                                socklen_t tolen);
-int setsockopt_reuseaddr(int fd);
+/* SO_REUSEADDR allows a server to rebind to an address that is already
+ * "in use" by old connections to e.g. previous server instance which is
+ * killed or crashed. Without it bind will fail until all such connections
+ * time out. Linux does not allow multiple live binds on same ip:port
+ * regardless of SO_REUSEADDR (unlike some other flavors of Unix).
+ * Turn it on before you call bind(). */
+void setsockopt_reuseaddr(int fd); /* On Linux this never fails. */
 int setsockopt_broadcast(int fd);
 /* NB: returns port in host byte order */
 unsigned bb_lookup_port(const char *port, const char *protocol, unsigned default_port);
@@ -318,6 +325,7 @@ int xsocket_stream(len_and_sockaddr **lsap);
  * numeric IP ("N.N.N.N") or numeric IPv6 address,
  * and can have ":PORT" suffix (for IPv6 use "[X:X:...:X]:PORT").
  * Only if there is no suffix, port argument is used */
+/* NB: these set SO_REUSEADDR before bind */
 int create_and_bind_stream_or_die(const char *bindaddr, int port);
 int create_and_bind_dgram_or_die(const char *bindaddr, int port);
 /* Create client TCP socket connected to peer:port. Peer cannot be NULL.
@@ -345,21 +353,21 @@ len_and_sockaddr* xhost_and_af2sockaddr(const char *host, int port, sa_family_t
 #define host_and_af2sockaddr(host, port, af) ((void)(af), host2sockaddr((host), (port)))
 #define xhost_and_af2sockaddr(host, port, af) ((void)(af), xhost2sockaddr((host), (port)))
 #endif
-/* Assign sin[6]_port member if the socket is of corresponding type,
+/* Assign sin[6]_port member if the socket is an AF_INET[6] one,
  * otherwise no-op. Useful for ftp.
  * NB: does NOT do htons() internally, just direct assignment. */
 void set_nport(len_and_sockaddr *lsa, unsigned port);
 /* Retrieve sin[6]_port or return -1 for non-INET[6] lsa's */
 int get_nport(const struct sockaddr *sa);
 /* Reverse DNS. Returns NULL on failure. */
-char* xmalloc_sockaddr2host(const struct sockaddr *sa, socklen_t salen);
+char* xmalloc_sockaddr2host(const struct sockaddr *sa);
 /* This one doesn't append :PORTNUM */
-char* xmalloc_sockaddr2host_noport(const struct sockaddr *sa, socklen_t salen);
+char* xmalloc_sockaddr2host_noport(const struct sockaddr *sa);
 /* This one also doesn't fall back to dotted IP (returns NULL) */
-char* xmalloc_sockaddr2hostonly_noport(const struct sockaddr *sa, socklen_t salen);
+char* xmalloc_sockaddr2hostonly_noport(const struct sockaddr *sa);
 /* inet_[ap]ton on steroids */
-char* xmalloc_sockaddr2dotted(const struct sockaddr *sa, socklen_t salen);
-char* xmalloc_sockaddr2dotted_noport(const struct sockaddr *sa, socklen_t salen);
+char* xmalloc_sockaddr2dotted(const struct sockaddr *sa);
+char* xmalloc_sockaddr2dotted_noport(const struct sockaddr *sa);
 // "old" (ipv4 only) API
 // users: traceroute.c hostname.c - use _list_ of all IPs
 struct hostent *xgethostbyname(const char *name);
@@ -579,10 +587,12 @@ enum {
 };
 #if BB_MMU
   void forkexit_or_rexec(void);
+  enum { re_execed = 0 };
 # define forkexit_or_rexec(argv)            forkexit_or_rexec()
 # define bb_daemonize_or_rexec(flags, argv) bb_daemonize_or_rexec(flags)
 # define bb_daemonize(flags)                bb_daemonize_or_rexec(flags, bogus)
 #else
+  void re_exec(char **argv) ATTRIBUTE_NORETURN;
   void forkexit_or_rexec(char **argv);
   extern bool re_execed;
 # define fork()          BUG_fork_is_unavailable_on_nommu()
@@ -601,8 +611,7 @@ extern const char *opt_complementary;
 extern const char *applet_long_options;
 #endif
 extern uint32_t option_mask32;
-/* TODO: don't pass argc, determine it by looking at argv */
-extern uint32_t getopt32(int argc, char **argv, const char *applet_opts, ...);
+extern uint32_t getopt32(char **argv, const char *applet_opts, ...);
 
 
 typedef struct llist_t {
@@ -634,8 +643,8 @@ enum { wrote_pidfile = 0 };
 
 enum {
        LOGMODE_NONE = 0,
-       LOGMODE_STDIO = 1<<0,
-       LOGMODE_SYSLOG = 1<<1,
+       LOGMODE_STDIO = (1 << 0),
+       LOGMODE_SYSLOG = (1 << 1) * ENABLE_FEATURE_SYSLOG,
        LOGMODE_BOTH = LOGMODE_SYSLOG + LOGMODE_STDIO,
 };
 extern const char *msg_eol;