Skip to content

Commit

Permalink
Link to libglib, use it in one place to start
Browse files Browse the repository at this point in the history
libglib is a hard requirement of other projects on the host, such
as libostree.  Let's make use of it, since it has a lot of useful
functionality for C programs.

Specifically, it aborts on OOM by default (because in practice anything that
isn't the kernel/pid 1 isn't going to be able to continue), so we can just use
`g_strdup()`.

(Note that it's required nowadays that `g_malloc() = malloc()`, so it's
 OK that we're passing this to `free()`.)
  • Loading branch information
cgwalters committed Nov 7, 2017
1 parent 51e7c50 commit a4efeaf
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
6 changes: 3 additions & 3 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ oci_umount_jsondir=/usr/share/containers/oci/hooks.d
oci_umount_options_DATA = oci-umount-options.conf
oci_umount_optionsdir=/usr/share/oci-umount/

oci_umount_CFLAGS = -Wall -Wextra -std=c99 $(YAJL_CFLAGS)
oci_umount_CFLAGS = -Wall -Wextra -std=c99
oci_umount_LDADD = $(YAJL_LIBS)
oci_umount_CFLAGS += $(SELINUX_CFLAGS)
oci_umount_LDADD += $(SELINUX_LIBS)
oci_umount_CFLAGS += $(SELINUX_CFLAGS) $(GLIB_CFLAGS)
oci_umount_LDADD += $(SELINUX_LIBS) $(GLIB_LIBS)

dist_man_MANS = oci-umount.1
EXTRA_DIST = README.md LICENSE
Expand Down
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ AM_PROG_CC_C_O
AC_USE_SYSTEM_EXTENSIONS
AC_SYS_LARGEFILE

PKG_CHECK_MODULES([GLIB], [gio-unix-2.0 >= 2.50])
PKG_CHECK_MODULES([YAJL], [yajl >= 2.0.0])
PKG_CHECK_MODULES([SELINUX], [libselinux >= 2.0.0])
PKG_CHECK_MODULES([LIBMOUNT], [mount >= 2.23.0])
Expand Down
7 changes: 2 additions & 5 deletions src/oci-umount.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#define _GNU_SOURCE
#include <glib.h>
#include <stdio.h>
#include <libgen.h>
#include <stdlib.h>
Expand Down Expand Up @@ -363,11 +364,7 @@ static int map_mount_host_to_container(const char *id, const struct config_mount
int ret;
unsigned nr_mapped = 0;

host_mnt_dup = strdup(host_mnt);
if (!host_mnt_dup) {
pr_perror("%s: strdup(%s) failed.", id, host_mnt);
return -1;
}
host_mnt_dup = g_strdup(host_mnt);

str = host_mnt_dup;
do {
Expand Down

0 comments on commit a4efeaf

Please sign in to comment.