shared,core: add "nm-errno.h"

This will be our extension on top of <errno.h>.

We want to use (integer) error numbers, that can both
contain native errors from <errno.h> and our own defines,
both merge in one domain. That is, we will reserve a small
range of integers for our own defines (that hopefully won't
clash with errors from <errno.h>).

We can use this at places where GError is too cumbersome to use.

The advantage is, that our error numbers extend <errno.h> and can
be mixed.

This is what "src/platform/nm-netlink.h" already does with nl_errno(). Next,
the netlink errors from there will be merged into "nm-errno.h".

Also, platform has NMPlatformError, which are a distinct set of error
numbers. But these work differently in the sense that negative values
represent codes from <errno.h> and positive numbers are our own platform
specific defines. NMPlatformError will also be merged into "nm-errno.h".

"nm-errno.h" will unify the error handling of platform and netlink,
making it more similar to what we are used to from systemd, and give
room to extend it for our own purpose.
This commit is contained in:
Thomas Haller 2018-12-22 12:41:04 +01:00
parent 9e9320cc0f
commit 943dcba531
4 changed files with 54 additions and 0 deletions

View file

@ -302,6 +302,8 @@ shared_nm_utils_libnm_utils_base_la_SOURCES = \
shared/nm-utils/nm-dedup-multi.h \
shared/nm-utils/nm-enum-utils.c \
shared/nm-utils/nm-enum-utils.h \
shared/nm-utils/nm-errno.c \
shared/nm-utils/nm-errno.h \
shared/nm-utils/nm-glib.h \
shared/nm-utils/nm-hash-utils.c \
shared/nm-utils/nm-hash-utils.h \

View file

@ -87,6 +87,7 @@ shared_files_libnm_core = files('''
nm-utils/c-list-util.c
nm-utils/nm-dedup-multi.c
nm-utils/nm-enum-utils.c
nm-utils/nm-errno.c
nm-utils/nm-hash-utils.c
nm-utils/nm-io-utils.c
nm-utils/nm-random-utils.c

View file

@ -0,0 +1,25 @@
/* NetworkManager -- Network link manager
*
* 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 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.
*
* Copyright 2018 Red Hat, Inc.
*/
#include "nm-default.h"
#include "nm-errno.h"
/*****************************************************************************/

View file

@ -0,0 +1,26 @@
/* NetworkManager -- Network link manager
*
* 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 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.
*
* Copyright 2018 Red Hat, Inc.
*/
#ifndef __NM_ERRNO_H__
#define __NM_ERRNO_H__
#include <errno.h>
#endif /* __NM_ERRNO_H__ */