Azure / azure-iot-sdk-c

A C99 SDK for connecting devices to Microsoft Azure IoT services
https://azure.github.io/azure-iot-sdk-c
Other
585 stars 739 forks source link

Azure firmware upgrade doesn't start, application exits in this function "device_run_service() " #131

Closed Konark411 closed 6 years ago

Konark411 commented 7 years ago

Device Details -TI Sitara am437x -ARM Cortex A9 -OS Ubuntu 14.04 -Azure C SDK version 1.1.13 (release_2017_04_21)

Description of the issue:

We want to use the firmware upgrade feature of azure c SDK using MQTT protocol for carrying out firmware upgrade on our device. After cross-compilation of SDK the generated library files are integrated in our device environment . The files "iothub_client_sample_mqtt_dm.c" and "pi.c " are used by application for firmware upgrade. The issue here is that the device initiates the process but sticks up in a particular function "device_run_service() " in the code ; the print logs under the code doesn't print anything. So need to understand this function named as "device_run_service() " in "pi.c " file . Now we have commented the function and we are able to move ahead till a point that is we are able to enter this function "iothub_client_sample_mqtt_dm_run(connectionString, traceOn)" but now we face different error which sums up with the cloud not registering the device id on the azure iothub.We also start the server application but firmware upgrade doesn't start as expected. Can disabling " device_run_service() " function impact the functionality ? or is this function carrying out some device specific task which we need to modify as per our device ? What is the purpose of function " device_run_service() " ?

Code sample exhibiting the issue:

bool device_run_service(void) { int pid, sid; bool retValue;

HERE PRINTF HAS BEEN ADDED SO THAT FUNCTION ENTRY CAN BE KNOWN BUT PRINTF PRINTLOG NOTHING GIVES A PRINT. THIS IS ORIGINAL CODE WE HAVE BEEN USING THE SAME CODE BUT HAVE ADDED PRINTS AT THIS POINT

/ Fork off the parent process / pid = fork(); if (pid < 0) { LogError("failed to fork from parent process: %p\n", pid); retValue = false; } else { if (pid > 0) { / exit the parent process / exit(EXIT_SUCCESS); } else { / child process segment / / Change the file mode mask / umask(0);

        /* Create a new SID for the child process */
        sid = setuid(0);
        if (sid < 0)
        {
            retValue = false;
            LogError("failed to set sudo");
        }
        else
        {
            /* Change the current working directory */
            if ((chdir("/")) < 0)
            {
                LogError("failed to chdir to '/'");
                retValue = false;
            }
            else
            {
                /* Close out the standard file descriptors */
                if (close(STDIN_FILENO) != 0)
                {
                    LogError("failed to close standard input");
                }
                if (close(STDOUT_FILENO) != 0)
                {
                    LogError("failed to close standard output");
                }
                if (close(STDERR_FILENO) != 0)
                {
                    LogError("failed to close standard error");
                }

                retValue = true;
            }
            /* Allow time for all needed system services to initialize */
            ThreadAPI_Sleep(30000);
        }
    }
}
return retValue;

}

Console log of the issue:

mhshami01 commented 7 years ago

Hello @Konark411,

Thank you for submitting this inquiry.

1- The 'device_runservice()' function, as implemented for pi, will transform the application into a daemon - https://en.wikipedia.org/wiki/Daemon(computing). You will not see any printf output because the code deliberately closes stdout, and stderr. 2- Since FirmwareUpdate is a platform specific operation, the sample app shows one very specific way of implementing the feature. As such, you must read and follow the steps in the https://github.com/Azure/azure-iot-sdk-c/blob/master/iothub_client/samples/iothub_client_sample_mqtt_dm/pi_device/readme.md file in order for the sample app to work.

Sincerely, --Haitham