libisofs  1.5.4
About: libisofs is a library to create an ISO 9660 filesystem, supports extensions like RockRidge or Joliet, makes bootable ISO 9660, and records file attributes which are of interest for data backups.
  Fossies Dox: libisofs-1.5.4.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

libiso_msgs.c File Reference
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/time.h>
#include "libiso_msgs.h"
Include dependency graph for libiso_msgs.c:

Go to the source code of this file.

Macros

#define LIBISO_MSGS_H_INTERNAL   1
 

Functions

static int libiso_msgs_item_new (struct libiso_msgs_item **item, struct libiso_msgs_item *link, int flag)
 
int libiso_msgs_item_unlink (struct libiso_msgs_item *o, struct libiso_msgs_item **chain_start, struct libiso_msgs_item **chain_end, int flag)
 Detaches item from its queue and eventually readjusts start, end pointers of the queue. More...
 
int libiso_msgs_item_destroy (struct libiso_msgs_item **item, int flag)
 
int libiso_msgs_item_get_msg (struct libiso_msgs_item *item, int *error_code, char **msg_text, int *os_errno, int flag)
 Obtain from a message item the three application oriented components as submitted with the originating call of libiso_msgs_submit(). More...
 
int libiso_msgs_item_get_origin (struct libiso_msgs_item *item, double *timestamp, pid_t *process_id, int *origin, int flag)
 Obtain from a message item the submitter identification submitted with the originating call of libiso_msgs_submit(). More...
 
int libiso_msgs_item_get_rank (struct libiso_msgs_item *item, int *severity, int *priority, int flag)
 Obtain from a message item severity and priority as submitted with the originating call of libiso_msgs_submit(). More...
 
int libiso_msgs_new (struct libiso_msgs **m, int flag)
 Create new empty message handling facility with queue and issue a first official reference to it. More...
 
static int libiso_msgs_lock (struct libiso_msgs *m, int flag)
 
static int libiso_msgs_unlock (struct libiso_msgs *m, int flag)
 
int libiso_msgs_destroy (struct libiso_msgs **m, int flag)
 Destroy a message handling facility and all its eventual messages. More...
 
int libiso_msgs_refer (struct libiso_msgs **pt, struct libiso_msgs *m, int flag)
 Create an official reference to an existing libiso_msgs object. More...
 
int libiso_msgs_set_severities (struct libiso_msgs *m, int queue_severity, int print_severity, char *print_id, int flag)
 Set minimum severity for messages to be queued (default LIBISO_MSGS_SEV_ALL) and for messages to be printed directly to stderr (default LIBISO_MSGS_SEV_NEVER). More...
 
int libiso_msgs__text_to_sev (char *severity_name, int *severity, int flag)
 Convert a severity name into a severity number,. More...
 
int libiso_msgs__sev_to_text (int severity, char **severity_name, int flag)
 Convert a registered severity number into a severity name. More...
 
int libiso_msgs_submit (struct libiso_msgs *m, int origin, int error_code, int severity, int priority, char *msg_text, int os_errno, int flag)
 Submit a message to a message handling facility. More...
 
int libiso_msgs_obtain (struct libiso_msgs *m, struct libiso_msgs_item **item, int severity, int priority, int flag)
 Obtain a message item that has at least the given severity and priority. More...
 
int libiso_msgs_destroy_item (struct libiso_msgs *m, struct libiso_msgs_item **item, int flag)
 Destroy a message item obtained by libiso_msgs_obtain(). More...
 

Macro Definition Documentation

◆ LIBISO_MSGS_H_INTERNAL

#define LIBISO_MSGS_H_INTERNAL   1

Definition at line 21 of file libiso_msgs.c.

Function Documentation

◆ libiso_msgs__sev_to_text()

int libiso_msgs__sev_to_text ( int  severity,
char **  severity_name,
int  flag 
)

Convert a registered severity number into a severity name.

Parameters
flagBitfield for control purposes: bit0= list all severity names in a blank separated string
Returns
>0 success, <=0 failure

Definition at line 286 of file libiso_msgs.c.

288 {
289  if(flag&1) {
290  *severity_name= "ALL ERRFILE DEBUG UPDATE NOTE HINT WARNING SORRY MISHAP FAILURE FATAL ABORT NEVER";
291  return(1);
292  }
293  *severity_name= "";
294  if(severity>=LIBISO_MSGS_SEV_NEVER)
295  *severity_name= "NEVER";
296  else if(severity>=LIBISO_MSGS_SEV_ABORT)
297  *severity_name= "ABORT";
298  else if(severity>=LIBISO_MSGS_SEV_FATAL)
299  *severity_name= "FATAL";
300  else if(severity>=LIBISO_MSGS_SEV_FAILURE)
301  *severity_name= "FAILURE";
302  else if(severity>=LIBISO_MSGS_SEV_MISHAP)
303  *severity_name= "MISHAP";
304  else if(severity>=LIBISO_MSGS_SEV_SORRY)
305  *severity_name= "SORRY";
306  else if(severity>=LIBISO_MSGS_SEV_WARNING)
307  *severity_name= "WARNING";
308  else if(severity>=LIBISO_MSGS_SEV_HINT)
309  *severity_name= "HINT";
310  else if(severity>=LIBISO_MSGS_SEV_NOTE)
311  *severity_name= "NOTE";
312  else if(severity>=LIBISO_MSGS_SEV_UPDATE)
313  *severity_name= "UPDATE";
314  else if(severity>=LIBISO_MSGS_SEV_DEBUG)
315  *severity_name= "DEBUG";
316  else if(severity>=LIBISO_MSGS_SEV_ERRFILE)
317  *severity_name= "ERRFILE";
318  else if(severity>=LIBISO_MSGS_SEV_ALL)
319  *severity_name= "ALL";
320  else {
321  *severity_name= "";
322  return(0);
323  }
324  return(1);
325 }
#define LIBISO_MSGS_SEV_FATAL
An error message which puts the whole operation of the program in question.
Definition: libiso_msgs.h:222
#define LIBISO_MSGS_SEV_ABORT
A message from an abort handler which will finally finish libburn.
Definition: libiso_msgs.h:227
#define LIBISO_MSGS_SEV_FAILURE
Non-fatal error indicating that an important part of an action failed and that only a new setup of pr...
Definition: libiso_msgs.h:210
#define LIBISO_MSGS_SEV_ALL
Use this to get messages of any severity.
Definition: libiso_msgs.h:126
#define LIBISO_MSGS_SEV_ERRFILE
Messages of this severity shall transport plain disk file paths whenever an event of severity SORRY o...
Definition: libiso_msgs.h:138
#define LIBISO_MSGS_SEV_UPDATE
Update of a progress report about long running actions.
Definition: libiso_msgs.h:147
#define LIBISO_MSGS_SEV_SORRY
Non-fatal error messages indicating that parts of an action failed but processing may go on if one ac...
Definition: libiso_msgs.h:181
#define LIBISO_MSGS_SEV_WARNING
Warnings about problems which could not be handled optimally.
Definition: libiso_msgs.h:159
#define LIBISO_MSGS_SEV_MISHAP
A FAILURE (see below) which can be tolerated during long lasting operations just because they cannot ...
Definition: libiso_msgs.h:195
#define LIBISO_MSGS_SEV_NOTE
Not so usual events which were gracefully handled.
Definition: libiso_msgs.h:151
#define LIBISO_MSGS_SEV_HINT
Possibilities to achieve a better result.
Definition: libiso_msgs.h:155
#define LIBISO_MSGS_SEV_DEBUG
Debugging messages not to be visible to normal users by default.
Definition: libiso_msgs.h:143
#define LIBISO_MSGS_SEV_NEVER
A severity to exclude or discard any possible message.
Definition: libiso_msgs.h:232

References LIBISO_MSGS_SEV_ABORT, LIBISO_MSGS_SEV_ALL, LIBISO_MSGS_SEV_DEBUG, LIBISO_MSGS_SEV_ERRFILE, LIBISO_MSGS_SEV_FAILURE, LIBISO_MSGS_SEV_FATAL, LIBISO_MSGS_SEV_HINT, LIBISO_MSGS_SEV_MISHAP, LIBISO_MSGS_SEV_NEVER, LIBISO_MSGS_SEV_NOTE, LIBISO_MSGS_SEV_SORRY, LIBISO_MSGS_SEV_UPDATE, and LIBISO_MSGS_SEV_WARNING.

Referenced by iso_obtain_msgs(), iso_sev_to_text(), and libiso_msgs_submit().

◆ libiso_msgs__text_to_sev()

int libiso_msgs__text_to_sev ( char *  severity_name,
int *  severity,
int  flag 
)

Convert a severity name into a severity number,.

Parameters
flagBitfield for control purposes (unused yet, submit 0)
Returns
>0 success, <=0 failure

Definition at line 249 of file libiso_msgs.c.

251 {
252  if(strncmp(severity_name,"NEVER",5)==0)
253  *severity= LIBISO_MSGS_SEV_NEVER;
254  else if(strncmp(severity_name,"ABORT",5)==0)
255  *severity= LIBISO_MSGS_SEV_ABORT;
256  else if(strncmp(severity_name,"FATAL",5)==0)
257  *severity= LIBISO_MSGS_SEV_FATAL;
258  else if(strncmp(severity_name,"FAILURE",7)==0)
259  *severity= LIBISO_MSGS_SEV_FAILURE;
260  else if(strncmp(severity_name,"MISHAP",6)==0)
261  *severity= LIBISO_MSGS_SEV_MISHAP;
262  else if(strncmp(severity_name,"SORRY",5)==0)
263  *severity= LIBISO_MSGS_SEV_SORRY;
264  else if(strncmp(severity_name,"WARNING",7)==0)
265  *severity= LIBISO_MSGS_SEV_WARNING;
266  else if(strncmp(severity_name,"HINT",4)==0)
267  *severity= LIBISO_MSGS_SEV_HINT;
268  else if(strncmp(severity_name,"NOTE",4)==0)
269  *severity= LIBISO_MSGS_SEV_NOTE;
270  else if(strncmp(severity_name,"UPDATE",6)==0)
271  *severity= LIBISO_MSGS_SEV_UPDATE;
272  else if(strncmp(severity_name,"DEBUG",5)==0)
273  *severity= LIBISO_MSGS_SEV_DEBUG;
274  else if(strncmp(severity_name,"ERRFILE",7)==0)
275  *severity= LIBISO_MSGS_SEV_ERRFILE;
276  else if(strncmp(severity_name,"ALL",3)==0)
277  *severity= LIBISO_MSGS_SEV_ALL;
278  else {
279  *severity= LIBISO_MSGS_SEV_ALL;
280  return(0);
281  }
282  return(1);
283 }

References LIBISO_MSGS_SEV_ABORT, LIBISO_MSGS_SEV_ALL, LIBISO_MSGS_SEV_DEBUG, LIBISO_MSGS_SEV_ERRFILE, LIBISO_MSGS_SEV_FAILURE, LIBISO_MSGS_SEV_FATAL, LIBISO_MSGS_SEV_HINT, LIBISO_MSGS_SEV_MISHAP, LIBISO_MSGS_SEV_NEVER, LIBISO_MSGS_SEV_NOTE, LIBISO_MSGS_SEV_SORRY, LIBISO_MSGS_SEV_UPDATE, and LIBISO_MSGS_SEV_WARNING.

Referenced by iso_msgs_submit(), iso_obtain_msgs(), iso_set_abort_severity(), iso_set_msgs_severities(), and iso_text_to_sev().

◆ libiso_msgs_destroy()

int libiso_msgs_destroy ( struct libiso_msgs **  m,
int  flag 
)

Destroy a message handling facility and all its eventual messages.

The submitted pointer gets set to NULL. Actually only the last destroy call of all official references to the object will really dispose it. All others just decrement the reference counter. Call this function only with official reference pointers obtained by libiso_msgs_new() or libiso_msgs_refer(), and only once per such pointer.

Parameters
flagBitfield for control purposes (unused yet, submit 0)
Returns
1 for success, 0 for pointer to NULL, -1 for fatal error

Definition at line 190 of file libiso_msgs.c.

191 {
192  struct libiso_msgs *o;
193  struct libiso_msgs_item *item, *next_item;
194 
195  o= *m;
196  if(o==NULL)
197  return(0);
198  if(o->refcount > 1) {
199  if(libiso_msgs_lock(*m,0)<=0)
200  return(-1);
201  o->refcount--;
202  libiso_msgs_unlock(*m,0);
203  *m= NULL;
204  return(1);
205  }
206 
207 #ifndef LIBISO_MSGS_SINGLE_THREADED
208  if(pthread_mutex_destroy(&(o->lock_mutex))!=0) {
209  pthread_mutex_unlock(&(o->lock_mutex));
210  pthread_mutex_destroy(&(o->lock_mutex));
211  }
212 #endif
213 
214  for(item= o->oldest; item!=NULL; item= next_item) {
215  next_item= item->next;
216  libiso_msgs_item_destroy(&item,0);
217  }
218  free((char *) o);
219  *m= NULL;
220  return(1);
221 }
int libiso_msgs_item_destroy(struct libiso_msgs_item **item, int flag)
Definition: libiso_msgs.c:86
static int libiso_msgs_lock(struct libiso_msgs *m, int flag)
Definition: libiso_msgs.c:160
static int libiso_msgs_unlock(struct libiso_msgs *m, int flag)
Definition: libiso_msgs.c:175

References libiso_msgs_item_destroy(), libiso_msgs_lock(), and libiso_msgs_unlock().

Referenced by iso_finish().

◆ libiso_msgs_destroy_item()

int libiso_msgs_destroy_item ( struct libiso_msgs *  m,
struct libiso_msgs_item **  item,
int  flag 
)

Destroy a message item obtained by libiso_msgs_obtain().

The submitted pointer gets set to NULL. Caution: Copy eventually obtained msg_text before destroying the item, if you want to use it further.

Parameters
flagBitfield for control purposes (unused yet, submit 0)
Returns
1 for success, 0 for pointer to NULL, <0 for severe errors

Definition at line 430 of file libiso_msgs.c.

432 {
433  int ret;
434 
435  ret= libiso_msgs_lock(m,0);
436  if(ret<=0)
437  return(-1);
438  ret= libiso_msgs_item_destroy(item,0);
439  libiso_msgs_unlock(m,0);
440  return(ret);
441 }

References libiso_msgs_item_destroy(), libiso_msgs_lock(), and libiso_msgs_unlock().

Referenced by iso_obtain_msgs().

◆ libiso_msgs_item_destroy()

int libiso_msgs_item_destroy ( struct libiso_msgs_item **  item,
int  flag 
)

Definition at line 86 of file libiso_msgs.c.

88 {
89  struct libiso_msgs_item *o;
90 
91  o= *item;
92  if(o==NULL)
93  return(0);
94  libiso_msgs_item_unlink(o,NULL,NULL,0);
95  if(o->msg_text!=NULL)
96  free((char *) o->msg_text);
97  free((char *) o);
98  *item= NULL;
99  return(1);
100 }
int libiso_msgs_item_unlink(struct libiso_msgs_item *o, struct libiso_msgs_item **chain_start, struct libiso_msgs_item **chain_end, int flag)
Detaches item from its queue and eventually readjusts start, end pointers of the queue.
Definition: libiso_msgs.c:67

References libiso_msgs_item_unlink().

Referenced by libiso_msgs_destroy(), libiso_msgs_destroy_item(), libiso_msgs_obtain(), and libiso_msgs_submit().

◆ libiso_msgs_item_get_msg()

int libiso_msgs_item_get_msg ( struct libiso_msgs_item *  item,
int *  error_code,
char **  msg_text,
int *  os_errno,
int  flag 
)

Obtain from a message item the three application oriented components as submitted with the originating call of libiso_msgs_submit().

Caution: msg_text becomes a pointer into item, not a copy.

Parameters
flagBitfield for control purposes (unused yet, submit 0)
Returns
1 on success, 0 on invalid item, <0 for servere errors

Definition at line 103 of file libiso_msgs.c.

106 {
107  *error_code= item->error_code;
108  *msg_text= item->msg_text;
109  *os_errno= item->os_errno;
110  return(1);
111 }

Referenced by iso_obtain_msgs().

◆ libiso_msgs_item_get_origin()

int libiso_msgs_item_get_origin ( struct libiso_msgs_item *  item,
double *  timestamp,
pid_t *  process_id,
int *  origin,
int  flag 
)

Obtain from a message item the submitter identification submitted with the originating call of libiso_msgs_submit().

Parameters
flagBitfield for control purposes (unused yet, submit 0)
Returns
1 on success, 0 on invalid item, <0 for servere errors

Definition at line 114 of file libiso_msgs.c.

117 {
118  *timestamp= item->timestamp;
119  *process_id= item->process_id;
120  *origin= item->origin;
121  return(1);
122 }

Referenced by iso_obtain_msgs().

◆ libiso_msgs_item_get_rank()

int libiso_msgs_item_get_rank ( struct libiso_msgs_item *  item,
int *  severity,
int *  priority,
int  flag 
)

Obtain from a message item severity and priority as submitted with the originating call of libiso_msgs_submit().

Parameters
flagBitfield for control purposes (unused yet, submit 0)
Returns
1 on success, 0 on invalid item, <0 for servere errors

Definition at line 125 of file libiso_msgs.c.

127 {
128  *severity= item->severity;
129  *priority= item->priority;
130  return(1);
131 }

Referenced by iso_obtain_msgs().

◆ libiso_msgs_item_new()

static int libiso_msgs_item_new ( struct libiso_msgs_item **  item,
struct libiso_msgs_item *  link,
int  flag 
)
static

Definition at line 30 of file libiso_msgs.c.

32 {
33  int ret;
34  struct libiso_msgs_item *o;
35  struct timeval tv;
36 
37  (*item)= o=
38  (struct libiso_msgs_item *) malloc(sizeof(struct libiso_msgs_item));
39  if(o==NULL)
40  return(-1);
41  o->timestamp= 0.0;
42  ret= gettimeofday(&tv, NULL);
43  if(ret==0)
44  o->timestamp= tv.tv_sec+0.000001*tv.tv_usec;
45  o->process_id= getpid();
46  o->origin= -1;
47  o->severity= LIBISO_MSGS_SEV_ALL;
48  o->priority= LIBISO_MSGS_PRIO_ZERO;
49  o->error_code= 0;
50  o->msg_text= NULL;
51  o->os_errno= 0;
52  o->prev= link;
53  o->next= NULL;
54  if(link!=NULL) {
55  if(link->next!=NULL) {
56  link->next->prev= o;
57  o->next= link->next;
58  }
59  link->next= o;
60  }
61  return(1);
62 }
#define LIBISO_MSGS_PRIO_ZERO
Definition: libiso_msgs.h:239

References LIBISO_MSGS_PRIO_ZERO, and LIBISO_MSGS_SEV_ALL.

Referenced by libiso_msgs_submit().

◆ libiso_msgs_item_unlink()

int libiso_msgs_item_unlink ( struct libiso_msgs_item *  o,
struct libiso_msgs_item **  chain_start,
struct libiso_msgs_item **  chain_end,
int  flag 
)

Detaches item from its queue and eventually readjusts start, end pointers of the queue.

Definition at line 67 of file libiso_msgs.c.

70 {
71  if(o->prev!=NULL)
72  o->prev->next= o->next;
73  if(o->next!=NULL)
74  o->next->prev= o->prev;
75  if(chain_start!=NULL)
76  if(*chain_start == o)
77  *chain_start= o->next;
78  if(chain_end!=NULL)
79  if(*chain_end == o)
80  *chain_end= o->prev;
81  o->next= o->prev= NULL;
82  return(1);
83 }

Referenced by libiso_msgs_item_destroy(), and libiso_msgs_obtain().

◆ libiso_msgs_lock()

static int libiso_msgs_lock ( struct libiso_msgs *  m,
int  flag 
)
static

Definition at line 160 of file libiso_msgs.c.

161 {
162 
163 #ifndef LIBISO_MSGS_SINGLE_THREADED
164  int ret;
165 
166  ret= pthread_mutex_lock(&(m->lock_mutex));
167  if(ret!=0)
168  return(0);
169 #endif
170 
171  return(1);
172 }

Referenced by libiso_msgs_destroy(), libiso_msgs_destroy_item(), libiso_msgs_obtain(), libiso_msgs_refer(), libiso_msgs_set_severities(), and libiso_msgs_submit().

◆ libiso_msgs_new()

int libiso_msgs_new ( struct libiso_msgs **  m,
int  flag 
)

Create new empty message handling facility with queue and issue a first official reference to it.

Parameters
flagBitfield for control purposes (unused yet, submit 0)
Returns
>0 success, <=0 failure

Definition at line 137 of file libiso_msgs.c.

138 {
139  struct libiso_msgs *o;
140 
141  (*m)= o= (struct libiso_msgs *) malloc(sizeof(struct libiso_msgs));
142  if(o==NULL)
143  return(-1);
144  o->refcount= 1;
145  o->oldest= NULL;
146  o->youngest= NULL;
147  o->count= 0;
148  o->queue_severity= LIBISO_MSGS_SEV_ALL;
149  o->print_severity= LIBISO_MSGS_SEV_NEVER;
150  strcpy(o->print_id,"libiso: ");
151 
152 #ifndef LIBISO_MSGS_SINGLE_THREADED
153  pthread_mutex_init(&(o->lock_mutex),NULL);
154 #endif
155 
156  return(1);
157 }

References LIBISO_MSGS_SEV_ALL, and LIBISO_MSGS_SEV_NEVER.

Referenced by iso_init_with_flag().

◆ libiso_msgs_obtain()

int libiso_msgs_obtain ( struct libiso_msgs *  m,
struct libiso_msgs_item **  item,
int  severity,
int  priority,
int  flag 
)

Obtain a message item that has at least the given severity and priority.

Usually all older messages of lower severity are discarded then. If no item of sufficient severity was found, all others are discarded from the queue.

Parameters
flagBitfield for control purposes (unused yet, submit 0)
Returns
1 if a matching item was found, 0 if not, <0 for severe errors

Definition at line 396 of file libiso_msgs.c.

398 {
399  int ret;
400  struct libiso_msgs_item *im, *next_im= NULL;
401 
402  *item= NULL;
403  ret= libiso_msgs_lock(m,0);
404  if(ret<=0)
405  return(-1);
406  for(im= m->oldest; im!=NULL; im= next_im) {
407  for(; im!=NULL; im= next_im) {
408  next_im= im->next;
409  if(im->severity>=severity)
410  break;
411  libiso_msgs_item_unlink(im,&(m->oldest),&(m->youngest),0);
412  libiso_msgs_item_destroy(&im,0); /* severity too low: delete */
413  }
414  if(im==NULL)
415  break;
416  if(im->priority>=priority)
417  break;
418  }
419  if(im==NULL)
420  {ret= 0; goto ex;}
421  libiso_msgs_item_unlink(im,&(m->oldest),&(m->youngest),0);
422  *item= im;
423  ret= 1;
424 ex:;
425  libiso_msgs_unlock(m,0);
426  return(ret);
427 }

References libiso_msgs_item_destroy(), libiso_msgs_item_unlink(), libiso_msgs_lock(), and libiso_msgs_unlock().

Referenced by iso_obtain_msgs().

◆ libiso_msgs_refer()

int libiso_msgs_refer ( struct libiso_msgs **  pt,
struct libiso_msgs *  o,
int  flag 
)

Create an official reference to an existing libiso_msgs object.

The references keep the object alive at least until it is released by a matching number of destroy calls. So each reference MUST be revoked by exactly one call to libiso_msgs_destroy().

Parameters
ptThe pointer to be set and registered
mA pointer to the existing object
flagBitfield for control purposes (unused yet, submit 0)
Returns
1 for success, 0 for failure

Definition at line 224 of file libiso_msgs.c.

225 {
226  if(libiso_msgs_lock(m,0)<=0)
227  return(0);
228  m->refcount++;
229  *pt= m;
230  libiso_msgs_unlock(m,0);
231  return(1);
232 }

References libiso_msgs_lock(), and libiso_msgs_unlock().

◆ libiso_msgs_set_severities()

int libiso_msgs_set_severities ( struct libiso_msgs *  m,
int  queue_severity,
int  print_severity,
char *  print_id,
int  flag 
)

Set minimum severity for messages to be queued (default LIBISO_MSGS_SEV_ALL) and for messages to be printed directly to stderr (default LIBISO_MSGS_SEV_NEVER).

Parameters
print_idA text of at most 80 characters to be printed before any eventually printed message (default is "libiso: ").
flagBitfield for control purposes (unused yet, submit 0)
Returns
always 1 for now

Definition at line 235 of file libiso_msgs.c.

237 {
238  if(libiso_msgs_lock(m,0)<=0)
239  return(0);
240  m->queue_severity= queue_severity;
241  m->print_severity= print_severity;
242  strncpy(m->print_id,print_id,80);
243  m->print_id[80]= 0;
244  libiso_msgs_unlock(m,0);
245  return(1);
246 }

References libiso_msgs_lock(), and libiso_msgs_unlock().

Referenced by iso_init_with_flag(), and iso_set_msgs_severities().

◆ libiso_msgs_submit()

int libiso_msgs_submit ( struct libiso_msgs *  m,
int  origin,
int  error_code,
int  severity,
int  priority,
char *  msg_text,
int  os_errno,
int  flag 
)

Submit a message to a message handling facility.

Parameters
originprogram specific identification number of the originator of a message. E.g. drive number. Programs should have an own range of origin numbers. See above LIBISO_MSGS_ORIGIN_*_BASE Use -1 if no number is known.
error_codeUnique error code. Use only registered codes. See below. The same unique error_code may be issued at different occasions but those should be equivalent out of the view of a libiso_msgs application. (E.g. "cannot open ATA drive" versus "cannot open SCSI drive" would be equivalent.)
severityThe LIBISO_MSGS_SEV_* of the event.
priorityThe LIBISO_MSGS_PRIO_* number of the event.
msg_textPrintable and human readable message text.
os_errnoEventual error code from operating system (0 if none)
flagBitfield for control purposes (unused yet, submit 0)
Returns
1 on success, 0 on rejection, <0 for severe errors

Definition at line 328 of file libiso_msgs.c.

331 {
332  int ret;
333  char *textpt,*sev_name,sev_text[81];
334  struct libiso_msgs_item *item= NULL;
335 
336  if(severity >= m->print_severity) {
337  if(msg_text==NULL)
338  textpt= "";
339  else
340  textpt= msg_text;
341  sev_text[0]= 0;
342  ret= libiso_msgs__sev_to_text(severity,&sev_name,0);
343  if(ret>0)
344  sprintf(sev_text,"%s : ",sev_name);
345 
346  fprintf(stderr,"%s%s%s\n",m->print_id,sev_text,textpt);
347  if(os_errno!=0) {
348  ret= libiso_msgs_lock(m,0);
349  if(ret<=0)
350  return(-1);
351  fprintf(stderr,"%s( Most recent system error: %d '%s' )\n",
352  m->print_id,os_errno,strerror(os_errno));
353  libiso_msgs_unlock(m,0);
354  }
355 
356  }
357  if(severity < m->queue_severity)
358  return(0);
359 
360  ret= libiso_msgs_lock(m,0);
361  if(ret<=0)
362  return(-1);
363  ret= libiso_msgs_item_new(&item,m->youngest,0);
364  if(ret<=0)
365  goto failed;
366  item->origin= origin;
367  item->error_code= error_code;
368  item->severity= severity;
369  item->priority= priority;
370  if(msg_text!=NULL) {
371  item->msg_text= malloc(strlen(msg_text)+1);
372  if(item->msg_text==NULL)
373  goto failed;
374  strcpy(item->msg_text,msg_text);
375  }
376  item->os_errno= os_errno;
377  if(m->oldest==NULL)
378  m->oldest= item;
379  m->youngest= item;
380  m->count++;
381  libiso_msgs_unlock(m,0);
382 
383 /*
384 fprintf(stderr,"libiso_experimental: message submitted to queue (now %d)\n",
385  m->count);
386 */
387 
388  return(1);
389 failed:;
390  libiso_msgs_item_destroy(&item,0);
391  libiso_msgs_unlock(m,0);
392  return(-1);
393 }
static int libiso_msgs_item_new(struct libiso_msgs_item **item, struct libiso_msgs_item *link, int flag)
Definition: libiso_msgs.c:30
int libiso_msgs__sev_to_text(int severity, char **severity_name, int flag)
Convert a registered severity number into a severity name.
Definition: libiso_msgs.c:286

References libiso_msgs__sev_to_text(), libiso_msgs_item_destroy(), libiso_msgs_item_new(), libiso_msgs_lock(), and libiso_msgs_unlock().

Referenced by iso_msg_debug(), iso_msg_submit(), iso_msgs_submit(), and iso_report_errfile().

◆ libiso_msgs_unlock()

static int libiso_msgs_unlock ( struct libiso_msgs *  m,
int  flag 
)
static

Definition at line 175 of file libiso_msgs.c.

176 {
177 
178 #ifndef LIBISO_MSGS_SINGLE_THREADED
179  int ret;
180 
181  ret= pthread_mutex_unlock(&(m->lock_mutex));
182  if(ret!=0)
183  return(0);
184 #endif
185 
186  return(1);
187 }

Referenced by libiso_msgs_destroy(), libiso_msgs_destroy_item(), libiso_msgs_obtain(), libiso_msgs_refer(), libiso_msgs_set_severities(), and libiso_msgs_submit().