Skip to content
This repository was archived by the owner on Oct 23, 2021. It is now read-only.

Commit a0b9049

Browse files
committed
v0.10 First release
1 parent a89898b commit a0b9049

File tree

7 files changed

+44
-8
lines changed

7 files changed

+44
-8
lines changed

Changes

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
v0.10 2015-11-01
2+
* First release
3+
* Hide important data
4+
* More intuitive output
5+
16
v0.01 2015-10-22
2-
* first version
7+
* First version
38

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22
# ==============================================================================
3-
# This to build project (but do not install)
3+
# This to build project
44
# ==============================================================================
55

66
curdir=$(dirname $(readlink -f $0))

src/config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#ifndef __CONFIG_H__
2020
#define __CONFIG_H__
2121

22+
#define VERSION ("0.10")
23+
2224
#define SUDODEV_GROUP ("sudodev")
2325
#define SUDOERS ("/etc/sudoers")
2426
#define SUDO_CONF ("/etc/sudoers.d/sudodev")

src/lockfile.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,19 @@ hasLockfile (void)
7171
return 1; /* A sudodevd is running */
7272
}
7373

74-
ftruncate (fd, 0);
74+
if (-1 == ftruncate (fd, 0))
75+
{
76+
say (mode, MSG_E, "ftruncate failed: %s", strerror (errno));
77+
// Do nothing but show error message
78+
}
79+
80+
/* Write pid to LOCKFILE */
7581
sprintf (pid, "%d", getpid ());
76-
write (fd, pid, strlen (pid) + 1);
82+
if (-1 == write (fd, pid, strlen (pid) + 1))
83+
{
84+
say (mode, MSG_E, "write failed: %s\n", strerror (errno));
85+
return -1;
86+
}
7787

7888
return 0;
7989
}

src/say.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <fcntl.h>
2424
#include <unistd.h>
2525
#include <syslog.h>
26+
#include <errno.h>
2627
#include <sys/param.h>
2728
#include "say.h"
2829
#include "config.h"
@@ -76,7 +77,12 @@ getSayMode (saymode_t * const mode)
7677
{
7778
memset (file, 0, sizeof (file));
7879
snprintf (link, MAXPATHLEN - len - 1, "%s/%d", path, index);
79-
readlink (link, file, MAXPATHLEN - 1);
80+
if (-1 == readlink (link, file, MAXPATHLEN - 1))
81+
{
82+
fprintf (stderr, "readlink failed: %s\n", strerror (errno));
83+
break;
84+
}
85+
8086
if (!strcmp (null, file))
8187
{
8288
/* If any file descriptor of 0, 1, 2 point to /dev/null,

src/sudodev.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ usage (const char * const string)
6262
int line;
6363
const char * const text[] =
6464
{
65+
"This is sudodev, version ", VERSION, "\n",
66+
"\n",
6567
"Usage: sudodev [add|del]\n",
6668
"\n",
6769
" add:\tadd a device for none-password sudo\n",
@@ -265,7 +267,12 @@ add (void)
265267
while (1)
266268
{
267269
say (mode, MSG_I, "Choose a device (q to quit): ");
268-
fgets (buff, (1 << 10) - 1, stdin);
270+
271+
if (!fgets (buff, (1 << 10) - 1, stdin))
272+
{
273+
say (mode, MSG_E, "fgets failed: %s\n", strerror (errno));
274+
return -1;
275+
}
269276
buff[strlen (buff) - 1] = 0;
270277

271278
if ('q' == *buff)
@@ -442,6 +449,7 @@ del (void)
442449
for (index = 0; devices[index]; ++index)
443450
{
444451
say (mode, MSG_I, "[%3d] %s", index + 1, devices[index]->name);
452+
445453
if (!(strncmp (UNKNOWNSTR, devices[index]->name, UNKNOWNSTRLEN)))
446454
{
447455
strncpy (buff, devices[index]->uuid, 8);
@@ -456,7 +464,11 @@ del (void)
456464
while (1)
457465
{
458466
say (mode, MSG_I, "Choose a device (q to quit): ");
459-
fgets (buff, (1 << 10) - 1, stdin);
467+
if (!fgets (buff, (1 << 10) - 1, stdin))
468+
{
469+
say (mode, MSG_E, "fgets failed: %s\n", strerror (errno));
470+
return -1;
471+
}
460472
buff[strlen (buff) - 1] = 0;
461473

462474
if ('q' == *buff)

src/sudodevd.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ main (const int argc, const char * const * const argv)
417417
}
418418
if (hasLock)
419419
{
420-
say (mode, MSG_E, "sudodevd is already running\n");
420+
say (mode, MSG_E, "sudodevd is already running, quit\n");
421421
exit (1);
422422
}
423423

@@ -484,6 +484,7 @@ main (const int argc, const char * const * const argv)
484484
}
485485

486486
/* Loop for event */
487+
say (mode, MSG_I, "starting sudodevd, version %s\n", VERSION);
487488
eventloop ();
488489

489490
say (mode, MSG_E, "Should never reach here, abort\n");

0 commit comments

Comments
 (0)