Last change
on this file since 3736 was 3509, checked in by Bruno Cornec, 9 years ago |
- Change mr_msg_int interface by adding the FUNCTION macro
- Use mr_msg in mr_system
- Ability to use that new log system everywhere now
|
-
Property svn:eol-style
set to
native
|
File size:
956 bytes
|
Line | |
---|
1 | /*
|
---|
2 | * $Id$
|
---|
3 | *
|
---|
4 | * Code (c)2006-2016 Bruno Cornec <bruno@mondorescue.org>
|
---|
5 | *
|
---|
6 | * Main file of mr_sys : a very small and simple
|
---|
7 | * library for system management
|
---|
8 | *
|
---|
9 | * Provided under the GPLv2
|
---|
10 | */
|
---|
11 |
|
---|
12 | #ifndef _GNU_SOURCE
|
---|
13 | #define _GNU_SOURCE
|
---|
14 | #endif
|
---|
15 |
|
---|
16 | #include <stdio.h>
|
---|
17 | #include <stdlib.h>
|
---|
18 |
|
---|
19 | #include "mr_err.h"
|
---|
20 | #include "mr_msg.h"
|
---|
21 | #include "mr_mem.h"
|
---|
22 |
|
---|
23 | /*
|
---|
24 | * Function that calls system in a sure way
|
---|
25 | */
|
---|
26 | int mr_system_int(int line, const char *file, const char *fmt, ...) {
|
---|
27 |
|
---|
28 | char *cmd = NULL;
|
---|
29 | int res = 0;
|
---|
30 | va_list args;
|
---|
31 |
|
---|
32 | va_start(args,fmt);
|
---|
33 | /*
|
---|
34 | printf("Format : %s\n",fmt);
|
---|
35 | */
|
---|
36 | res = vasprintf(&cmd, fmt, args);
|
---|
37 | if (res == -1) {
|
---|
38 | mr_msg_int(1,line,file,"mr_system_int","Unable to alloc memory in mr_system_int\nExiting...");
|
---|
39 | mr_exit(-1,"Unable to alloc memory in mr_system_int");
|
---|
40 | }
|
---|
41 | /*
|
---|
42 | printf("Command : %s\n",cmd);
|
---|
43 | */
|
---|
44 | res = system(cmd);
|
---|
45 | if (res < 0 ) {
|
---|
46 | mr_msg(4, "Unable to execute %s",cmd);
|
---|
47 | }
|
---|
48 | mr_free(cmd);
|
---|
49 | va_end(args);
|
---|
50 | return(res);
|
---|
51 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.