Thread (10 messages) 10 messages, 2 authors, 2012-11-30

Re: [PATCH v2 7/8] adaptername: Refactor adaptername_init/exit to fix exit path

From: Anderson Lizardo <hidden>
Date: 2012-11-30 13:22:09

Hi Szymon,

On Fri, Nov 30, 2012 at 8:57 AM, Szymon Janc [off-list ref] wrote:
        inot_fd = inotify_init();
        if (inot_fd < 0) {
-               error("Failed to setup inotify");
-               return 0;
+               int err = errno;
+               error("Failed to setup inotify: %s (%d)", strerror(-err), -err);
+               return -err;
Now it is broken :) By convention, "err" should be always negative, so use:

int err = -errno;

when printing the error, you need to make it positive, like above:

error("Failed to setup inotify: %s (%d)", strerror(-err), -err);

then when returning, use:

return err;

See other examples on the bluez code if you have doubts.
quoted hunk ↗ jump to hunk
@@ -290,30 +301,38 @@ static int adaptername_init(void)

        watch_d = inotify_add_watch(inot_fd, MACHINE_INFO_DIR, mask);
        if (watch_d < 0) {
-               error("Failed to setup watch for '%s'", MACHINE_INFO_DIR);
+               int err = errno;
+               error("Failed to setup watch for '%s': %s (%d)",
+                               MACHINE_INFO_DIR, strerror(-err), -err);
                close(inot_fd);
-               return 0;
+               return -err;
        }
Same problem here, please fix. (you can send just a v3 of this patch,
it should not conflict with others).

Regards,
-- 
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help