fault: get fault.c ready for use by s4
[samba.git] / lib / util / util.h
index e1160d5a3e4e7dfe07ea13a6800280e6db87aba2..b143e4e9919a46ec70c24ea817581b19cdca8a3c 100644 (file)
 #ifndef _SAMBA_UTIL_H_
 #define _SAMBA_UTIL_H_
 
-#if _SAMBA_BUILD_ == 4
-#include "../lib/util/charset/charset.h"
-#endif
-#include "../lib/util/attr.h"
+#include "lib/util/charset/charset.h"
+#include "lib/util/attr.h"
 
 /* for TALLOC_CTX */
 #include <talloc.h>
@@ -39,12 +37,11 @@ struct smbsrv_tcon;
 extern const char *logfile;
 extern const char *panic_action;
 
-#include "../lib/util/time.h"
-#include "../lib/util/data_blob.h"
-#include "../lib/util/xfile.h"
-#include "../lib/util/mutex.h"
-#include "../lib/util/byteorder.h"
-#include "../lib/util/talloc_stack.h"
+#include "lib/util/time.h"
+#include "lib/util/data_blob.h"
+#include "lib/util/xfile.h"
+#include "lib/util/byteorder.h"
+#include "lib/util/talloc_stack.h"
 
 /**
  * assert macros 
@@ -60,18 +57,11 @@ extern const char *panic_action;
            __FILE__, __LINE__, #b)); }} while (0)
 #endif
 
-#if _SAMBA_BUILD_ == 4
-#ifdef VALGRIND
-#define strlen(x) valgrind_strlen(x)
-size_t valgrind_strlen(const char *s);
-#endif
-#endif
-
 #ifndef ABS
 #define ABS(a) ((a)>0?(a):(-(a)))
 #endif
 
-#include "../lib/util/memory.h"
+#include "lib/util/memory.h"
 
 /**
  * Write backtrace to debug log
@@ -83,12 +73,14 @@ _PUBLIC_ void call_backtrace(void);
 **/
 _PUBLIC_ _NORETURN_ void smb_panic(const char *why);
 
-#if _SAMBA_BUILD_ == 4
-/**
-setup our fault handlers
-**/
-_PUBLIC_ void fault_setup(const char *pname);
-#endif
+typedef void (*smb_panic_handler_t)(const char *why);
+
+_PUBLIC_ void fault_configure(smb_panic_handler_t panic_handler);
+_PUBLIC_ void fault_setup(void);
+_PUBLIC_ void fault_setup_disable(void);
+_PUBLIC_ void dump_core_setup(const char *progname, const char *logfile);
+_PUBLIC_ void smb_panic(const char *reason);
+
 
 /**
   register a fault handler. 
@@ -655,40 +647,13 @@ _PUBLIC_ int set_blocking(int fd, bool set);
 /**
  Sleep for a specified number of milliseconds.
 **/
-_PUBLIC_ void msleep(unsigned int t);
+_PUBLIC_ void smb_msleep(unsigned int t);
 
 /**
  Get my own name, return in talloc'ed storage.
 **/
 _PUBLIC_ char* get_myname(TALLOC_CTX *mem_ctx);
 
-/**
- Return true if a string could be a pure IP address.
-**/
-_PUBLIC_ bool is_ipaddress(const char *str);
-
-/**
- Interpret an internet address or name into an IP address in 4 byte form.
-**/
-_PUBLIC_ uint32_t interpret_addr(const char *str);
-
-/**
- A convenient addition to interpret_addr().
-**/
-_PUBLIC_ struct in_addr interpret_addr2(const char *str);
-
-/**
- Check if an IP is the 0.0.0.0.
-**/
-_PUBLIC_ bool is_zero_ip_v4(struct in_addr ip);
-
-/**
- Are two IPs on the same subnet?
-**/
-_PUBLIC_ bool same_net_v4(struct in_addr ip1,struct in_addr ip2,struct in_addr mask);
-
-_PUBLIC_ bool is_ipaddress_v4(const char *str);
-
 /**
  Check if a process exists. Does this work on all unixes?
 **/
@@ -700,6 +665,14 @@ _PUBLIC_ bool process_exists_by_pid(pid_t pid);
 **/
 _PUBLIC_ bool fcntl_lock(int fd, int op, off_t offset, off_t count, int type);
 
+/**
+ * Write dump of binary data to a callback
+ */
+void dump_data_cb(const uint8_t *buf, int len,
+                 bool omit_zero_bytes,
+                 void (*cb)(const char *buf, void *private_data),
+                 void *private_data);
+
 /**
  * Write dump of binary data to the log file.
  *
@@ -798,15 +771,6 @@ int ms_fnmatch(const char *pattern, const char *string, enum protocol_types prot
 int gen_fnmatch(const char *pattern, const char *string);
 #endif
 
-/* The following definitions come from lib/util/mutex.c  */
-
-
-/**
-  register a set of mutex/rwlock handlers. 
-  Should only be called once in the execution of smbd.
-*/
-_PUBLIC_ bool register_mutex_handlers(const char *name, struct mutex_ops *ops);
-
 /* The following definitions come from lib/util/idtree.c  */
 
 
@@ -854,7 +818,7 @@ _PUBLIC_ void close_low_fds(bool stderr_too);
 /**
  Become a daemon, discarding the controlling terminal.
 **/
-_PUBLIC_ void become_daemon(bool do_fork, bool no_process_group);
+_PUBLIC_ void become_daemon(bool do_fork, bool no_process_group, bool log_stdout);
 
 /**
  * Load a ini-style file.
@@ -867,6 +831,9 @@ bool pm_process( const char *fileName,
 bool unmap_file(void *start, size_t size);
 
 void print_asc(int level, const uint8_t *buf,int len);
+void print_asc_cb(const uint8_t *buf, int len,
+                 void (*cb)(const char *buf, void *private_data),
+                 void *private_data);
 
 /**
  * Add an id to an array of ids.
@@ -876,9 +843,15 @@ void print_asc(int level, const uint8_t *buf,int len);
  */
 
 bool add_uid_to_array_unique(TALLOC_CTX *mem_ctx, uid_t uid,
-                            uid_t **uids, size_t *num_uids);
+                            uid_t **uids, uint32_t *num_uids);
 bool add_gid_to_array_unique(TALLOC_CTX *mem_ctx, gid_t gid,
-                            gid_t **gids, size_t *num_gids);
+                            gid_t **gids, uint32_t *num_gids);
+
+/**
+ * Allocate anonymous shared memory of the given size
+ */
+void *anonymous_shared_allocate(size_t bufsz);
+void anonymous_shared_free(void *ptr);
 
 /*
   run a command as a child process, with a timeout.
@@ -899,4 +872,8 @@ struct tevent_req *samba_runcmd_send(TALLOC_CTX *mem_ctx,
                                     const char * const *argv0, ...);
 int samba_runcmd_recv(struct tevent_req *req, int *perrno);
 
+#ifdef DEVELOPER
+void samba_start_debugger(void);
+#endif
+
 #endif /* _SAMBA_UTIL_H_ */