@@ -300,6 +300,24 @@ package sdjournal
300300// return sd_journal_get_catalog(j, ret);
301301// }
302302//
303+ // int
304+ // my_sd_id128_get_boot(void *f, sd_id128_t *boot_id)
305+ // {
306+ // int(*sd_id128_get_boot)(sd_id128_t *);
307+ //
308+ // sd_id128_get_boot = f;
309+ // return sd_id128_get_boot(boot_id);
310+ // }
311+ //
312+ // char *
313+ // my_sd_id128_to_string(void *f, sd_id128_t boot_id, char s[_SD_ARRAY_STATIC SD_ID128_STRING_MAX])
314+ // {
315+ // char *(*sd_id128_to_string)(sd_id128_t, char *);
316+ //
317+ // sd_id128_to_string = f;
318+ // return sd_id128_to_string(boot_id, s);
319+ // }
320+ //
303321import "C"
304322import (
305323 "bytes"
@@ -1118,3 +1136,33 @@ func (j *Journal) GetCatalog() (string, error) {
11181136
11191137 return catalog , nil
11201138}
1139+
1140+ // GetBootID get systemd boot id
1141+ func (j * Journal ) GetBootID () (string , error ) {
1142+ sd_id128_get_boot , err := getFunction ("sd_id128_get_boot" )
1143+ if err != nil {
1144+ return "" , err
1145+ }
1146+
1147+ var boot_id C.sd_id128_t
1148+ r := C .my_sd_id128_get_boot (sd_id128_get_boot , & boot_id )
1149+ if r < 0 {
1150+ return "" , fmt .Errorf ("failed to get boot id: %s" , syscall .Errno (- r ).Error ())
1151+ }
1152+
1153+ sd_id128_to_string , err := getFunction ("sd_id128_to_string" )
1154+ if err != nil {
1155+ return "" , err
1156+ }
1157+
1158+ c := (* C .char )(C .malloc (33 ))
1159+ defer C .free (unsafe .Pointer (c ))
1160+ C .my_sd_id128_to_string (sd_id128_to_string , boot_id , c )
1161+
1162+ bootID := C .GoString (c )
1163+ if len (bootID ) <= 0 {
1164+ return "" , fmt .Errorf ("get boot id %s is not valid" , bootID )
1165+ }
1166+
1167+ return bootID , nil
1168+ }
0 commit comments