@@ -1481,6 +1481,7 @@ int flb_utils_get_machine_id(char **out_id, size_t *out_size)
14811481 char * id ;
14821482 size_t bytes ;
14831483 char * uuid ;
1484+ int fallback = FLB_FALSE ;
14841485
14851486#ifdef __linux__
14861487 char * dbus_var = "/var/lib/dbus/machine-id" ;
@@ -1490,6 +1491,11 @@ int flb_utils_get_machine_id(char **out_id, size_t *out_size)
14901491 if (access (dbus_var , F_OK ) == 0 ) { /* check if the file exists first */
14911492 ret = machine_id_read_and_sanitize (dbus_var , & id , & bytes );
14921493 if (ret == 0 ) {
1494+ if (bytes == 0 ) {
1495+ /* guid is somewhat corrupted */
1496+ fallback = FLB_TRUE ;
1497+ goto fallback ;
1498+ }
14931499 * out_id = id ;
14941500 * out_size = bytes ;
14951501 return 0 ;
@@ -1500,6 +1506,11 @@ int flb_utils_get_machine_id(char **out_id, size_t *out_size)
15001506 if (access (dbus_etc , F_OK ) == 0 ) { /* check if the file exists first */
15011507 ret = machine_id_read_and_sanitize (dbus_etc , & id , & bytes );
15021508 if (ret == 0 ) {
1509+ if (bytes == 0 ) {
1510+ /* guid is somewhat corrupted */
1511+ fallback = FLB_TRUE ;
1512+ goto fallback ;
1513+ }
15031514 * out_id = id ;
15041515 * out_size = bytes ;
15051516 return 0 ;
@@ -1595,6 +1606,8 @@ int flb_utils_get_machine_id(char **out_id, size_t *out_size)
15951606 }
15961607#endif
15971608
1609+ fallback :
1610+
15981611 flb_warn ("falling back on random machine UUID" );
15991612
16001613 /* generate a random uuid */
@@ -1607,6 +1620,9 @@ int flb_utils_get_machine_id(char **out_id, size_t *out_size)
16071620 if (ret == 0 ) {
16081621 * out_id = uuid ;
16091622 * out_size = strlen (uuid );
1623+ if (fallback == FLB_TRUE ) {
1624+ return 2 ;
1625+ }
16101626 return 0 ;
16111627 }
16121628
0 commit comments