-
Notifications
You must be signed in to change notification settings - Fork 32
Add support for snappy #250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,17 +30,16 @@ | |
| #include <sys/types.h> | ||
| #include <errno.h> | ||
| #include <unistd.h> | ||
| #include <stdlib.h> | ||
|
|
||
| #include <glib.h> | ||
|
|
||
| #define OFONO_API_SUBJECT_TO_CHANGE | ||
| #include <ofono/modem.h> | ||
| #include <ofono/gprs-provision.h> | ||
|
|
||
| #ifndef MBPI_DATABASE | ||
| #define MBPI_DATABASE "/usr/share/mobile-broadband-provider-info/" \ | ||
| "serviceproviders.xml" | ||
| #endif | ||
| #define MBPI_FILE "serviceproviders.xml" | ||
| #define MBPI_DATABASE "/usr/share/mobile-broadband-provider-info/" MBPI_FILE | ||
|
|
||
| #include "mbpi.h" | ||
|
|
||
|
|
@@ -110,7 +109,7 @@ static void mbpi_g_set_error(GMarkupParseContext *context, GError **error, | |
|
|
||
| va_end(ap); | ||
|
|
||
| g_prefix_error(error, "%s:%d ", MBPI_DATABASE, line_number); | ||
| g_prefix_error(error, "%s:%d ", MBPI_FILE, line_number); | ||
| } | ||
|
|
||
| static void text_handler(GMarkupParseContext *context, | ||
|
|
@@ -565,34 +564,40 @@ static gboolean mbpi_parse(const GMarkupParser *parser, gpointer userdata, | |
| char *db; | ||
| int fd; | ||
| GMarkupParseContext *context; | ||
| gboolean ret; | ||
| gboolean ret = FALSE; | ||
| const char *snap; | ||
| char *filename; | ||
|
|
||
| /* SNAP is a path to our data in snappy systems */ | ||
| snap = getenv("SNAP"); | ||
| filename = g_strdup_printf("%s%s", snap ? snap : "", MBPI_DATABASE); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should discuss where mbpi ends up living as it's used by modemmanager too. I think it probably should live in it's own snap that shares the file via content sharing. We also should explore the ability for an end-user to modify this file on a working system ( ie. allow a writable version that would override the default ) vs. forcing the user to report a bug and wait for an official update. |
||
|
|
||
| fd = open(MBPI_DATABASE, O_RDONLY); | ||
| fd = open(filename, O_RDONLY); | ||
| if (fd < 0) { | ||
| g_set_error(error, G_FILE_ERROR, | ||
| g_file_error_from_errno(errno), | ||
| "open(%s) failed: %s", MBPI_DATABASE, | ||
| "open(%s) failed: %s", filename, | ||
| g_strerror(errno)); | ||
| return FALSE; | ||
| goto done; | ||
| } | ||
|
|
||
| if (fstat(fd, &st) < 0) { | ||
| close(fd); | ||
| g_set_error(error, G_FILE_ERROR, | ||
| g_file_error_from_errno(errno), | ||
| "fstat(%s) failed: %s", MBPI_DATABASE, | ||
| "fstat(%s) failed: %s", filename, | ||
| g_strerror(errno)); | ||
| return FALSE; | ||
| goto done; | ||
| } | ||
|
|
||
| db = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0); | ||
| if (db == MAP_FAILED) { | ||
| close(fd); | ||
| g_set_error(error, G_FILE_ERROR, | ||
| g_file_error_from_errno(errno), | ||
| "mmap(%s) failed: %s", MBPI_DATABASE, | ||
| "mmap(%s) failed: %s", filename, | ||
| g_strerror(errno)); | ||
| return FALSE; | ||
| goto done; | ||
| } | ||
|
|
||
| context = g_markup_parse_context_new(parser, | ||
|
|
@@ -608,6 +613,8 @@ static gboolean mbpi_parse(const GMarkupParser *parser, gpointer userdata, | |
| close(fd); | ||
| g_markup_parse_context_free(context); | ||
|
|
||
| done: | ||
| g_free(filename); | ||
| return ret; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1107,12 +1107,20 @@ static void parse_config(void) | |
| char **modems; | ||
| int i; | ||
| const char *filename; | ||
| char *snap_filename = NULL; | ||
| const char *conf_override = getenv("OFONO_PHONESIM_CONFIG"); | ||
| /* SNAP_COMMON gives us a writable path for daemons in snappy systems */ | ||
| const char *snap_common = getenv("SNAP_COMMON"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a short comment explaining why SNAP_COMMON is used here. |
||
|
|
||
| char *conf_override = getenv("OFONO_PHONESIM_CONFIG"); | ||
| if (conf_override) | ||
| if (conf_override) { | ||
| filename = conf_override; | ||
| else | ||
| } else if (snap_common) { | ||
| snap_filename = g_strdup_printf("%s/etc/phonesim.conf", | ||
| snap_common); | ||
| filename = snap_filename; | ||
| } else { | ||
| filename = CONFIGDIR "/phonesim.conf"; | ||
| } | ||
|
|
||
| DBG("filename %s", filename); | ||
|
|
||
|
|
@@ -1143,6 +1151,9 @@ static void parse_config(void) | |
| g_strfreev(modems); | ||
|
|
||
| done: | ||
| if (snap_filename) | ||
| g_free(snap_filename); | ||
|
|
||
| g_key_file_free(keyfile); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a short comment that explains the SNAP env variable.