X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=common-src%2Futil.h;h=140982f5e45969d582e1f6fcc4f2b96fd40bfa65;hb=e676d2a937a46194f0bd97a130ae1a4138e8b4e9;hp=53082b6708b63de1ac73c988bcfa26dc3500ee4a;hpb=d5853102f67d85d8e169f9dbe973ad573306c215;p=debian%2Famanda diff --git a/common-src/util.h b/common-src/util.h index 53082b6..140982f 100644 --- a/common-src/util.h +++ b/common-src/util.h @@ -62,6 +62,15 @@ int connect_portrange(sockaddr_union *, in_port_t, in_port_t, char *, int bind_portrange(int, sockaddr_union *, in_port_t, in_port_t, char *); +/* just like an accept() call, but periodically calling PROLONG(PROLONG_DATA) and + * returning -1 with errno set to 0 if PROLONG returns false. Note that the socket + * need not be configured as non-blocking. + * + * Other arguments are just like for accept(2). + */ +int interruptible_accept(int sock, struct sockaddr *addr, socklen_t *addrlen, + gboolean (*prolong)(gpointer data), gpointer prolong_data); + ssize_t full_writev(int, struct iovec *, int); char * construct_datestamp(time_t *t); @@ -71,9 +80,11 @@ char * construct_timestamp(time_t *t); * always adds "" around the string */ #define quote_string(str) quote_string_maybe((str), 0) #define quote_string_always(str) quote_string_maybe((str), 1) +#define len_quote_string(str) len_quote_string_maybe((str), 0); /*@only@*//*@null@*/char *quote_string_maybe(const char *str, gboolean always); /*@only@*//*@null@*/char *unquote_string(const char *str); +/*@only@*//*@null@*/int len_quote_string_maybe(const char *str, gboolean always); /* Split a string into space-delimited words, obeying quoting as created by * quote_string. To keep compatibility with the old split(), this has the @@ -119,17 +130,8 @@ char * hexdecode_string(const char *str, GError **err); int copy_file(char *dst, char *src, char **errmsg); /* These two functions handle "braced alternates", which is a syntax borrowed, - * partially, from shells. Comma-separated strings enclosed in curly braces - * expand into multiple alternatives for the entire string. - * For example: - * - * "{foo,bar,bat}" -> [ "foo", "bar", "bat" ] - * "foo{1,2}bar" -> [ "foo1bar", "foo2bar" ] - * "foo{1\,2,3}bar" -> [ "foo1,2bar", "foo3bar" ] - * "{a,b}-{1,2}" -> [ "a-1", "a-2", "b-1", "b-2" ] - * - * Note that nested braces are not processed. Braces, commas, and backslashes - * may be escaped with backslashes. Returns NULL on invalid strings. + * partially, from shells. See perl/Amanda/Util.pod for a full description of + * the syntax they support. */ GPtrArray * expand_braced_alternates(char * source); char * collapse_braced_alternates(GPtrArray *source); @@ -184,10 +186,10 @@ int compare_possibly_null_strings(const char * a, const char * b); * not NULL. * * @param hostname: the hostname to start with + * @param socktype: the socket type (SOCK_DGRAM or SOCK_STREAM) * @param res: (result) if not NULL, the results from getaddrinfo() - * @param canonname: (result) if not NULL, the canonical name of the host - * @returns: newly allocated canonical hostname, or NULL if no - * canonical hostname was available. + * @param canonname: (result) if not NULL, the newly-allocated canonical name of the host + * @returns: 0 on success, otherwise a getaddrinfo result (for use with gai_strerror) */ int resolve_hostname(const char *hostname, int socktype, struct addrinfo **res, char **canonname); @@ -335,52 +337,37 @@ pcontext_t get_pcontext(void); * or prototypes some simple stub functions that are used instead. */ -#ifdef HAVE_READLINE -# ifdef HAVE_READLINE_READLINE_H +#ifdef HAVE_LIBREADLINE +# if defined(HAVE_READLINE_READLINE_H) # include -# ifdef HAVE_READLINE_HISTORY_H -# include -# endif -# else -# ifdef HAVE_READLINE_H -# include -# ifdef HAVE_HISTORY_H -# include -# endif -# endif -# endif -#else - -char * readline(const char *prompt); -void add_history(const char *line); - -#endif +# elif defined(HAVE_READLINE_H) +# include +# else /* !defined(HAVE_READLINE_H) */ +extern char *readline (); +# endif /* !defined(HAVE_READLINE_H) */ + /* char *cmdline = NULL; */ +#else /* !defined(HAVE_LIBREADLINE) */ + /* use our own readline */ +char * readline(const char *prompt); +#endif /* HAVE_LIBREADLINE */ + +#ifdef HAVE_READLINE_HISTORY +# if defined(HAVE_READLINE_HISTORY_H) +# include +# elif defined(HAVE_HISTORY_H) +# include +# else /* !defined(HAVE_HISTORY_H) */ +extern void add_history (); +extern int write_history (); +extern int read_history (); +# endif /* defined(HAVE_READLINE_HISTORY_H) */ +#else /* !defined(HAVE_READLINE_HISTORY) */ + /* use our own add_history */ +void add_history(const char *line); +#endif /* HAVE_READLINE_HISTORY */ char *base64_decode_alloc_string(char *); -/* A GHFunc (callback for g_hash_table_foreach), - * Count the number of properties. - * - * @param key_p: (char *) property name. - * @param value_p: (GSList *) property values list. - * @param user_data_p: (int *) count are added to that value. - */ -void count_proplist(gpointer key_p, - gpointer value_p, - gpointer user_data_p); - -/* A GHFunc (callback for g_hash_table_foreach), - * Store a property and it's value in an ARGV. - * - * @param key_p: (char *) property name. - * @param value_p: (GSList *) property values list. - * @param user_data_p: (char ***) pointer to ARGV. - */ -void proplist_add_to_argv(gpointer key_p, - gpointer value_p, - gpointer user_data_p); - - /* Inform the OpenBSD pthread library about the high-numbered file descriptors * that an amandad service inherits. This won't be necessary once the new * threading library is availble (OpenBSD 5.0?), but won't hurt anyway. See the @@ -391,10 +378,19 @@ void openbsd_fd_inform(void); #define openbsd_fd_inform() #endif +/* Add all properties to an ARGV + * + * @param argvchild: Pointer to the ARGV. + * @param proplist: The property list + */ +void property_add_to_argv(GPtrArray *argv_ptr, GHashTable *proplist); + /* Print the argv_ptr with g_debug() * * @param argv_ptr: GPtrArray of an array to print. */ void debug_executing(GPtrArray *argv_ptr); +/* execute the program and get the first line from stdout ot stderr */ +char *get_first_line(GPtrArray *argv_ptr); #endif /* UTIL_H */