Merge branch 'for-pierre-marc' of git://git.infradead.org/users/jblunck/ust
authorPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Tue, 27 Oct 2009 22:58:15 +0000 (18:58 -0400)
committerPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Tue, 27 Oct 2009 22:58:15 +0000 (18:58 -0400)
Fixed conflicts:
include/ust/marker.h

1  2 
include/ust/marker.h
libust/marker.c
libust/serialize.c
libust/tracectl.c
libust/tracer.h
ustd/ustd.c

diff --combined include/ust/marker.h
index 0000000000000000000000000000000000000000,2b5a0c38ba701dfe6f1874eecee097b6bbd47e5a..5c7d1b362b7b3f22dd153d1bdefab7ac3c09ee46
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,311 +1,328 @@@
 -              void *probe_private, void *call_private,
+ /*
+  * Code markup for dynamic and static tracing.
+  *
+  * See Documentation/marker.txt.
+  *
+  * (C) Copyright 2006 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
+  * (C) Copyright 2009 Pierre-Marc Fournier <pierre-marc dot fournier at polymtl dot ca>
+  *
+  * This library is free software; you can redistribute it and/or
+  * modify it under the terms of the GNU Lesser General Public
+  * License as published by the Free Software Foundation; either
+  * version 2.1 of the License, or (at your option) any later version.
+  *
+  * This library is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this library; if not, write to the Free Software
+  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+  */
+ #ifndef _LINUX_MARKER_H
+ #define _LINUX_MARKER_H
+ #include <stdarg.h>
+ //ust// #include <linux/types.h>
+ #include <ust/immediate.h>
+ //ust// #include <linux/ltt-channels.h>
+ #include <ust/kernelcompat.h>
+ #include <kcompat/list.h>
++#include "processor.h"
+ //ust// struct module;
+ //ust// struct task_struct;
+ struct marker;
+ /**
+  * marker_probe_func - Type of a marker probe function
+  * @mdata: marker data
+  * @probe_private: probe private data
+  * @call_private: call site private data
+  * @fmt: format string
+  * @args: variable argument list pointer. Use a pointer to overcome C's
+  *        inability to pass this around as a pointer in a portable manner in
+  *        the callee otherwise.
+  *
+  * Type of marker probe functions. They receive the mdata and need to parse the
+  * format string to recover the variable argument list.
+  */
+ typedef void marker_probe_func(const struct marker *mdata,
 -      void (*call)(const struct marker *mdata, void *call_private, ...);
++              void *probe_private, struct registers *regs, void *call_private,
+               const char *fmt, va_list *args);
+ struct marker_probe_closure {
+       marker_probe_func *func;        /* Callback */
+       void *probe_private;            /* Private probe data */
+ };
+ struct marker {
+       const char *channel;    /* Name of channel where to send data */
+       const char *name;       /* Marker name */
+       const char *format;     /* Marker format string, describing the
+                                * variable argument list.
+                                */
+       DEFINE_IMV(char, state);/* Immediate value state. */
+       char ptype;             /* probe type : 0 : single, 1 : multi */
+                               /* Probe wrapper */
+       u16 channel_id;         /* Numeric channel identifier, dynamic */
+       u16 event_id;           /* Numeric event identifier, dynamic */
 -                NULL, tp_name_str, tp_cb }
++      void (*call)(const struct marker *mdata, void *call_private, struct registers *regs, ...);
+       struct marker_probe_closure single;
+       struct marker_probe_closure *multi;
+       const char *tp_name;    /* Optional tracepoint name */
+       void *tp_cb;            /* Optional tracepoint callback */
++      void *location;         /* Address of marker in code */
+ } __attribute__((aligned(8)));
+ #define CONFIG_MARKERS
+ #ifdef CONFIG_MARKERS
+ #define _DEFINE_MARKER(channel, name, tp_name_str, tp_cb, format)     \
+               static const char __mstrtab_##channel##_##name[]        \
+               __attribute__((section("__markers_strings")))           \
+               = #channel "\0" #name "\0" format;                      \
++              struct registers regs;                                  \
+               static struct marker __mark_##channel##_##name          \
+               __attribute__((section("__markers"), aligned(8))) =     \
+               { __mstrtab_##channel##_##name,                         \
+                 &__mstrtab_##channel##_##name[sizeof(#channel)],      \
+                 &__mstrtab_##channel##_##name[sizeof(#channel) +      \
+                                               sizeof(#name)],         \
+                 0, 0, 0, 0, marker_probe_cb,                          \
+                 { __mark_empty_function, NULL},                       \
 -                                      call_private, ## args);         \
++                NULL, tp_name_str, tp_cb, NULL };                     \
++              asm (".section __marker_addr,\"aw\",@progbits\n\t"      \
++                     _ASM_PTR "%c[marker_struct], (1f)\n\t"           \
++                     ".previous\n\t"                                  \
++                     "1:\n\t"                                         \
++                      :: [marker_struct] "i" (&__mark_##channel##_##name));\
++              save_registers(&regs)
++
++
+ #define DEFINE_MARKER(channel, name, format)                          \
+               _DEFINE_MARKER(channel, name, NULL, NULL, format)
+ #define DEFINE_MARKER_TP(channel, name, tp_name, tp_cb, format)               \
+               _DEFINE_MARKER(channel, name, #tp_name, tp_cb, format)
+ /*
+  * Make sure the alignment of the structure in the __markers section will
+  * not add unwanted padding between the beginning of the section and the
+  * structure. Force alignment to the same alignment as the section start.
+  *
+  * The "generic" argument controls which marker enabling mechanism must be used.
+  * If generic is true, a variable read is used.
+  * If generic is false, immediate values are used.
+  */
+ #define __trace_mark(generic, channel, name, call_private, format, args...) \
+       do {                                                            \
+               DEFINE_MARKER(channel, name, format);                   \
+               __mark_check_format(format, ## args);                   \
+               if (!generic) {                                         \
+                       if (unlikely(imv_read(                          \
+                                       __mark_##channel##_##name.state))) \
+                               (*__mark_##channel##_##name.call)       \
+                                       (&__mark_##channel##_##name,    \
 -                                      call_private, ## args);         \
++                                      call_private, &regs, ## args);          \
+               } else {                                                \
+                       if (unlikely(_imv_read(                         \
+                                       __mark_##channel##_##name.state))) \
+                               (*__mark_##channel##_##name.call)       \
+                                       (&__mark_##channel##_##name,    \
 -                      call_private, ## args);                         \
++                                      call_private, &regs, ## args);          \
+               }                                                       \
+       } while (0)
+ #define __trace_mark_tp(channel, name, call_private, tp_name, tp_cb,  \
+                       format, args...)                                \
+       do {                                                            \
+               void __check_tp_type(void)                              \
+               {                                                       \
+                       register_trace_##tp_name(tp_cb);                \
+               }                                                       \
+               DEFINE_MARKER_TP(channel, name, tp_name, tp_cb, format);\
+               __mark_check_format(format, ## args);                   \
+               (*__mark_##channel##_##name.call)(&__mark_##channel##_##name, \
 -      void *call_private, ...);
++                      call_private, &regs, ## args);                          \
+       } while (0)
+ extern void marker_update_probe_range(struct marker *begin,
+       struct marker *end);
+ #define GET_MARKER(channel, name)     (__mark_##channel##_##name)
+ #else /* !CONFIG_MARKERS */
+ #define DEFINE_MARKER(channel, name, tp_name, tp_cb, format)
+ #define __trace_mark(generic, channel, name, call_private, format, args...) \
+               __mark_check_format(format, ## args)
+ #define __trace_mark_tp(channel, name, call_private, tp_name, tp_cb,  \
+               format, args...)                                        \
+       do {                                                            \
+               void __check_tp_type(void)                              \
+               {                                                       \
+                       register_trace_##tp_name(tp_cb);                \
+               }                                                       \
+               __mark_check_format(format, ## args);                   \
+       } while (0)
+ static inline void marker_update_probe_range(struct marker *begin,
+       struct marker *end)
+ { }
+ #define GET_MARKER(channel, name)
+ #endif /* CONFIG_MARKERS */
+ /**
+  * trace_mark - Marker using code patching
+  * @channel: marker channel (where to send the data), not quoted.
+  * @name: marker name, not quoted.
+  * @format: format string
+  * @args...: variable argument list
+  *
+  * Places a marker using optimized code patching technique (imv_read())
+  * to be enabled when immediate values are present.
+  */
+ #define trace_mark(channel, name, format, args...) \
+       __trace_mark(0, channel, name, NULL, format, ## args)
+ /**
+  * _trace_mark - Marker using variable read
+  * @channel: marker channel (where to send the data), not quoted.
+  * @name: marker name, not quoted.
+  * @format: format string
+  * @args...: variable argument list
+  *
+  * Places a marker using a standard memory read (_imv_read()) to be
+  * enabled. Should be used for markers in code paths where instruction
+  * modification based enabling is not welcome. (__init and __exit functions,
+  * lockdep, some traps, printk).
+  */
+ #define _trace_mark(channel, name, format, args...) \
+       __trace_mark(1, channel, name, NULL, format, ## args)
+ /**
+  * trace_mark_tp - Marker in a tracepoint callback
+  * @channel: marker channel (where to send the data), not quoted.
+  * @name: marker name, not quoted.
+  * @tp_name: tracepoint name, not quoted.
+  * @tp_cb: tracepoint callback. Should have an associated global symbol so it
+  *         is not optimized away by the compiler (should not be static).
+  * @format: format string
+  * @args...: variable argument list
+  *
+  * Places a marker in a tracepoint callback.
+  */
+ #define trace_mark_tp(channel, name, tp_name, tp_cb, format, args...) \
+       __trace_mark_tp(channel, name, NULL, tp_name, tp_cb, format, ## args)
+ /**
+  * MARK_NOARGS - Format string for a marker with no argument.
+  */
+ #define MARK_NOARGS " "
+ extern void lock_markers(void);
+ extern void unlock_markers(void);
+ extern void markers_compact_event_ids(void);
+ /* To be used for string format validity checking with gcc */
+ static inline void __printf(1, 2) ___mark_check_format(const char *fmt, ...)
+ {
+ }
+ #define __mark_check_format(format, args...)                          \
+       do {                                                            \
+               if (0)                                                  \
+                       ___mark_check_format(format, ## args);          \
+       } while (0)
+ extern marker_probe_func __mark_empty_function;
+ extern void marker_probe_cb(const struct marker *mdata,
 -extern int marker_register_lib(struct marker *markers_start,
 -                             int markers_count);
 -
 -#define MARKER_LIB                                                    \
 -extern struct marker __start___markers[] __attribute__((visibility("hidden")));       \
 -extern struct marker __stop___markers[] __attribute__((visibility("hidden")));                \
 -                                                                                      \
 -static void __attribute__((constructor)) __markers__init(void)                                \
 -{                                                                                     \
 -      marker_register_lib(__start___markers, (((long)__stop___markers)-((long)__start___markers))/sizeof(struct marker));\
++      void *call_private, struct registers *regs, ...);
+ /*
+  * Connect a probe to a marker.
+  * private data pointer must be a valid allocated memory address, or NULL.
+  */
+ extern int marker_probe_register(const char *channel, const char *name,
+       const char *format, marker_probe_func *probe, void *probe_private);
+ /*
+  * Returns the private data given to marker_probe_register.
+  */
+ extern int marker_probe_unregister(const char *channel, const char *name,
+       marker_probe_func *probe, void *probe_private);
+ /*
+  * Unregister a marker by providing the registered private data.
+  */
+ extern int marker_probe_unregister_private_data(marker_probe_func *probe,
+       void *probe_private);
+ extern void *marker_get_private_data(const char *channel, const char *name,
+       marker_probe_func *probe, int num);
+ /*
+  * marker_synchronize_unregister must be called between the last marker probe
+  * unregistration and the first one of
+  * - the end of module exit function
+  * - the free of any resource used by the probes
+  * to ensure the code and data are valid for any possibly running probes.
+  */
+ #define marker_synchronize_unregister() synchronize_sched()
+ struct marker_iter {
+ //ust//       struct module *module;
+       struct lib *lib;
+       struct marker *marker;
+ };
+ extern void marker_iter_start(struct marker_iter *iter);
+ extern void marker_iter_next(struct marker_iter *iter);
+ extern void marker_iter_stop(struct marker_iter *iter);
+ extern void marker_iter_reset(struct marker_iter *iter);
+ extern int marker_get_iter_range(struct marker **marker, struct marker *begin,
+       struct marker *end);
+ extern void marker_update_process(void);
+ extern int is_marker_enabled(const char *channel, const char *name);
+ //ust// #ifdef CONFIG_MARKERS_USERSPACE
+ //ust// extern void exit_user_markers(struct task_struct *p);
+ //ust// #else
+ //ust// static inline void exit_user_markers(struct task_struct *p)
+ //ust// {
+ //ust// }
+ //ust// #endif
++struct marker_addr {
++      struct marker *marker;
++      void *addr;
++};
+ struct lib {
+       struct marker *markers_start;
++      struct marker_addr *markers_addr_start;
+       int markers_count;
+       struct list_head list;
+ };
++extern int marker_register_lib(struct marker *markers_start, struct marker_addr *marker_addr_start, int markers_count);
++
++#define MARKER_LIB                                                                            \
++extern struct marker __start___markers[] __attribute__((visibility("hidden")));                       \
++extern struct marker __stop___markers[] __attribute__((visibility("hidden")));                        \
++extern struct marker_addr __start___marker_addr[] __attribute__((visibility("hidden")));      \
++extern struct marker_addr __stop___marker_addr[] __attribute__((visibility("hidden")));               \
++                                                                                              \
++static void __attribute__((constructor)) __markers__init(void)                                        \
++{                                                                                             \
++      marker_register_lib(__start___markers, __start___marker_addr, (((long)__stop___markers)-((long)__start___markers))/sizeof(struct marker)); \
+ }
+ extern void marker_set_new_marker_cb(void (*cb)(struct marker *));
+ extern void init_markers(void);
+ #endif
diff --combined libust/marker.c
index d4514f11a4f5faf4e34291c0839b4300c421c8f0,8690d2b1151e0a5861c2c81327226cb55e46757a..b543b166bcd52bd26928da736f69481e9b73c03d
@@@ -33,9 -33,9 +33,9 @@@
  #define _LGPL_SOURCE
  #include <urcu-bp.h>
  
- #include "kernelcompat.h"
+ #include <ust/kernelcompat.h>
  
- #include "marker.h"
+ #include <ust/marker.h>
  #include "usterr.h"
  #include "channels.h"
  #include "tracercore.h"
@@@ -43,8 -43,6 +43,8 @@@
  
  extern struct marker __start___markers[] __attribute__((visibility("hidden")));
  extern struct marker __stop___markers[] __attribute__((visibility("hidden")));
 +extern struct marker_addr __start___marker_addr[] __attribute__((visibility("hidden")));
 +extern struct marker_addr __stop___marker_addr[] __attribute__((visibility("hidden")));
  
  /* Set to 1 to enable marker debug output */
  static const int marker_debug;
@@@ -89,7 -87,7 +89,7 @@@ struct marker_entry 
        char *format;
        char *name;
                        /* Probe wrapper */
 -      void (*call)(const struct marker *mdata, void *call_private, ...);
 +      void (*call)(const struct marker *mdata, void *call_private, struct registers *regs, ...);
        struct marker_probe_closure single;
        struct marker_probe_closure *multi;
        int refcount;   /* Number of times armed. 0 if disarmed. */
@@@ -125,7 -123,7 +125,7 @@@ static void marker_update_processes(voi
   * operations that modifies the execution flow of preemptible code.
   */
  notrace void __mark_empty_function(const struct marker *mdata,
 -      void *probe_private, void *call_private, const char *fmt, va_list *args)
 +      void *probe_private, struct registers *regs, void *call_private, const char *fmt, va_list *args)
  {
  }
  //ust// EXPORT_SYMBOL_GPL(__mark_empty_function);
   * rcu_dereference() for the pointer read.
   */
  notrace void marker_probe_cb(const struct marker *mdata,
 -              void *call_private, ...)
 +              void *call_private, struct registers *regs, ...)
  {
        va_list args;
        char ptype;
                /* Must read the ptr before private data. They are not data
                 * dependant, so we put an explicit smp_rmb() here. */
                smp_rmb();
 -              va_start(args, call_private);
 -              func(mdata, mdata->single.probe_private, call_private,
 +              va_start(args, regs);
 +              func(mdata, mdata->single.probe_private, regs, call_private,
                        mdata->format, &args);
                va_end(args);
        } else {
                 */
                smp_read_barrier_depends();
                for (i = 0; multi[i].func; i++) {
 -                      va_start(args, call_private);
 +                      va_start(args, regs);
                        multi[i].func(mdata, multi[i].probe_private,
 -                              call_private, mdata->format, &args);
 +                              regs, call_private, mdata->format, &args);
                        va_end(args);
                }
        }
   * Should be connected to markers "MARK_NOARGS".
   */
  static notrace void marker_probe_cb_noarg(const struct marker *mdata,
 -              void *call_private, ...)
 +              void *call_private, struct registers *regs, ...)
  {
        va_list args;   /* not initialized */
        char ptype;
                /* Must read the ptr before private data. They are not data
                 * dependant, so we put an explicit smp_rmb() here. */
                smp_rmb();
 -              func(mdata, mdata->single.probe_private, call_private,
 +              func(mdata, mdata->single.probe_private, regs, call_private,
                        mdata->format, &args);
        } else {
                struct marker_probe_closure *multi;
                 */
                smp_read_barrier_depends();
                for (i = 0; multi[i].func; i++)
 -                      multi[i].func(mdata, multi[i].probe_private,
 +                      multi[i].func(mdata, multi[i].probe_private, regs,
                                call_private, mdata->format, &args);
        }
  //ust//       rcu_read_unlock_sched_notrace();
@@@ -825,7 -823,6 +825,7 @@@ int marker_probe_register(const char *c
        }
        mutex_unlock(&markers_mutex);
  
 +      /* Activate marker if necessary */
        marker_update_probes();
  
        mutex_lock(&markers_mutex);
@@@ -1498,22 -1495,15 +1498,22 @@@ static void new_markers(struct marker *
        }
  }
  
 -int marker_register_lib(struct marker *markers_start, int markers_count)
 +int marker_register_lib(struct marker *markers_start, struct marker_addr *marker_addr_start, int markers_count)
  {
        struct lib *pl;
 +      struct marker_addr *addr;
  
        pl = (struct lib *) malloc(sizeof(struct lib));
  
        pl->markers_start = markers_start;
 +      pl->markers_addr_start = marker_addr_start;
        pl->markers_count = markers_count;
  
 +      lock_markers();
 +      for(addr = marker_addr_start; addr < marker_addr_start + markers_count; addr++)
 +              addr->marker->location = addr->addr;
 +      unlock_markers();
 +
        /* FIXME: maybe protect this with its own mutex? */
        lock_markers();
        list_add(&pl->list, &libs);
@@@ -1542,8 -1532,8 +1542,8 @@@ static int initialized = 0
  void __attribute__((constructor)) init_markers(void)
  {
        if(!initialized) {
 -              marker_register_lib(__start___markers, (((long)__stop___markers)-((long)__start___markers))/sizeof(struct marker));
 -              DBG("markers_start: %p, markers_stop: %p\n", __start___markers, __stop___markers);
 +              marker_register_lib(__start___markers, __start___marker_addr, (((long)__stop___markers)-((long)__start___markers))/sizeof(struct marker));
 +              //DBG("markers_start: %p, markers_stop: %p\n", __start___markers, __stop___markers);
                initialized = 1;
        }
  }
diff --combined libust/serialize.c
index f9e45b60751ed8060640d004df92f19d7ef4dec8,99d4dce4194e076ea5644d9780a89f14ff33a480..beaf6390b544a4dd96f0b4c30afdb0692283435f
@@@ -32,7 -32,7 +32,7 @@@
  #include <string.h>
  #include <stdint.h>
  
- #include "kernelcompat.h"
+ #include <ust/kernelcompat.h>
  #define _LGPL_SOURCE
  #include <urcu-bp.h>
  #include <urcu/rculist.h>
@@@ -583,8 -583,7 +583,8 @@@ void ltt_write_event_data(struct rchan_
  
  
  notrace void ltt_vtrace(const struct marker *mdata, void *probe_data,
 -                      void *call_data, const char *fmt, va_list *args)
 +                      struct registers *regs, void *call_data,
 +                      const char *fmt, va_list *args)
  {
        int largest_align, ret;
        struct ltt_active_marker *pdata;
  }
  
  notrace void ltt_trace(const struct marker *mdata, void *probe_data,
 -                     void *call_data, const char *fmt, ...)
 +                     struct registers *regs, void *call_data,
 +                     const char *fmt, ...)
  {
        va_list args;
  
        va_start(args, fmt);
 -      ltt_vtrace(mdata, probe_data, call_data, fmt, &args);
 +      ltt_vtrace(mdata, probe_data, regs, call_data, fmt, &args);
        va_end(args);
  }
  
diff --combined libust/tracectl.c
index ed902574987cfa4cefceb7f53ea352dca787f35f,3d3bd485dffb51345007a128f37d188874be84ca..e28b3159d73c1408b58b072850f2bb89a45d59eb
@@@ -29,9 -29,9 +29,9 @@@
  
  #include <urcu-bp.h>
  
- #include "marker.h"
+ #include <ust/marker.h>
  #include "tracer.h"
- #include "localerr.h"
+ #include "usterr.h"
  #include "ustcomm.h"
  #include "relay.h" /* FIXME: remove */
  #include "marker-control.h"
@@@ -117,7 -117,7 +117,7 @@@ static void print_markers(FILE *fp
        marker_iter_start(&iter);
  
        while(iter.marker) {
 -              fprintf(fp, "marker: %s/%s %d \"%s\"\n", iter.marker->channel, iter.marker->name, (int)imv_read(iter.marker->state), iter.marker->format);
 +              fprintf(fp, "marker: %s/%s %d \"%s\" %p\n", iter.marker->channel, iter.marker->name, (int)imv_read(iter.marker->state), iter.marker->format, iter.marker->location);
                marker_iter_next(&iter);
        }
        unlock_markers();
@@@ -837,7 -837,7 +837,7 @@@ static void auto_probe_connect(struct m
        if(result && result != -EEXIST)
                ERR("ltt_marker_connect (marker = %s/%s, errno = %d)", m->channel, m->name, -result);
  
 -      DBG("auto connected marker %s %s to probe default", m->channel, m->name);
 +      DBG("auto connected marker %s (addr: %p) %s to probe default", m->channel, m, m->name);
  
  }
  
diff --combined libust/tracer.h
index b2ac930293badb95aaef2e66430fb847b5030f4c,cb84dad7e05332725a20a54b65b6d2cf9b82a9e3..502cdcce436b763e4ba06c7a6cfe00c55e6a54ed
  #include <sys/types.h>
  #include <stdarg.h>
  //#include "list.h"
- #include "kernelcompat.h"
+ #include <ust/kernelcompat.h>
  #include "buffer.h"
  #include "relay.h"
  #include "channels.h"
  #include "tracercore.h"
- #include "marker.h"
+ #include <ust/marker.h>
  
  /* Number of bytes to log with a read/write event */
  #define LTT_LOG_RW_SIZE                       32L
@@@ -110,9 -110,9 +110,9 @@@ struct ltt_active_marker 
  
  struct marker; //ust//
  extern void ltt_vtrace(const struct marker *mdata, void *probe_data,
 -      void *call_data, const char *fmt, va_list *args);
 +      struct registers *regs, void *call_data, const char *fmt, va_list *args);
  extern void ltt_trace(const struct marker *mdata, void *probe_data,
 -      void *call_data, const char *fmt, ...);
 +      struct registers *regs, void *call_data, const char *fmt, ...);
  
  /*
   * Unique ID assigned to each registered probe.
diff --combined ustd/ustd.c
index 858bdf52b46c9e21ac6bab46e358ff016c117505,0026c3b12a88816392df29447289d48404656d16..bfa6352e1ccf2b4063660ff279b007f29ec3702a
@@@ -33,9 -33,8 +33,8 @@@
  #include <getopt.h>
  
  #include "ustd.h"
- #include "localerr.h"
+ #include "usterr.h"
  #include "ustcomm.h"
- #include "share.h"
  
  /* return value: 0 = subbuffer is finished, it won't produce data anymore
   *               1 = got subbuffer successfully
@@@ -542,24 -541,6 +541,24 @@@ void sigterm_handler(int sig
        terminate_req = 1;
  }
  
 +static int write_pidfile(const char *file_name, pid_t pid)
 +{
 +      FILE *pidfp;
 +
 +      pidfp = fopen(file_name, "w+");
 +      if(!pidfp) {
 +              PERROR("fopen (%s)", pidfile);
 +              WARN("killing child process");
 +              return -1;
 +      }
 +
 +      fprintf(pidfp, "%d\n", pid);
 +
 +      fclose(pidfp);
 +
 +      return 0;
 +}
 +
  int start_ustd(int fd)
  {
        struct ustcomm_ustd ustd;
                return 1;
        }
  
 +      /* Write pidfile */
 +      if(pidfile) {
 +              result = write_pidfile(pidfile, getpid());
 +              if(result == -1) {
 +                      ERR("failed to write pidfile");
 +                      return 1;
 +              }
 +      }
 +
        /* Notify parent that we are successfully started. */
        if(fd != -1) {
                /* write any one character */
@@@ -701,6 -673,26 +700,6 @@@ int start_ustd_daemon(
                char buf;
                FILE *pidfp;
  
 -              /* It's important to write the file *before*
 -               * the parent ends, because the file may be
 -               * read as soon as the parent ends.
 -               */
 -              if(pidfile) {
 -                      pidfp = fopen(pidfile, "w+");
 -                      if(!pidfp) {
 -                              PERROR("fopen (%s)", pidfile);
 -                              WARN("killing child process");
 -                              result = kill(child_pid, SIGTERM);
 -                              if(result == -1) {
 -                                      PERROR("kill");
 -                              }
 -                              return -1;
 -                      }
 -
 -                      fprintf(pidfp, "%d\n", child_pid);
 -                      fclose(pidfp);
 -              }
 -
                result = read(fd[0], &buf, 1);
                if(result == -1) {
                        PERROR("read");
This page took 0.033821 seconds and 4 git commands to generate.