1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package dbus
16
17 import (
18 "context"
19 "errors"
20 "fmt"
21 "path"
22 "strconv"
23
24 "github.com/godbus/dbus/v5"
25 )
26
27
28 type Who string
29
30 const (
31
32 All Who = "all"
33
34 Main Who = "main"
35
36 Control Who = "control"
37 )
38
39 func (c *Conn) jobComplete(signal *dbus.Signal) {
40 var id uint32
41 var job dbus.ObjectPath
42 var unit string
43 var result string
44 dbus.Store(signal.Body, &id, &job, &unit, &result)
45 c.jobListener.Lock()
46 out, ok := c.jobListener.jobs[job]
47 if ok {
48 out <- result
49 delete(c.jobListener.jobs, job)
50 }
51 c.jobListener.Unlock()
52 }
53
54 func (c *Conn) startJob(ctx context.Context, ch chan<- string, job string, args ...interface{}) (int, error) {
55 if ch != nil {
56 c.jobListener.Lock()
57 defer c.jobListener.Unlock()
58 }
59
60 var p dbus.ObjectPath
61 err := c.sysobj.CallWithContext(ctx, job, 0, args...).Store(&p)
62 if err != nil {
63 return 0, err
64 }
65
66 if ch != nil {
67 c.jobListener.jobs[p] = ch
68 }
69
70
71 jobID, _ := strconv.Atoi(path.Base(string(p)))
72
73 return jobID, nil
74 }
75
76
77 func (c *Conn) StartUnit(name string, mode string, ch chan<- string) (int, error) {
78 return c.StartUnitContext(context.Background(), name, mode, ch)
79 }
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111 func (c *Conn) StartUnitContext(ctx context.Context, name string, mode string, ch chan<- string) (int, error) {
112 return c.startJob(ctx, ch, "org.freedesktop.systemd1.Manager.StartUnit", name, mode)
113 }
114
115
116 func (c *Conn) StopUnit(name string, mode string, ch chan<- string) (int, error) {
117 return c.StopUnitContext(context.Background(), name, mode, ch)
118 }
119
120
121
122 func (c *Conn) StopUnitContext(ctx context.Context, name string, mode string, ch chan<- string) (int, error) {
123 return c.startJob(ctx, ch, "org.freedesktop.systemd1.Manager.StopUnit", name, mode)
124 }
125
126
127 func (c *Conn) ReloadUnit(name string, mode string, ch chan<- string) (int, error) {
128 return c.ReloadUnitContext(context.Background(), name, mode, ch)
129 }
130
131
132
133 func (c *Conn) ReloadUnitContext(ctx context.Context, name string, mode string, ch chan<- string) (int, error) {
134 return c.startJob(ctx, ch, "org.freedesktop.systemd1.Manager.ReloadUnit", name, mode)
135 }
136
137
138 func (c *Conn) RestartUnit(name string, mode string, ch chan<- string) (int, error) {
139 return c.RestartUnitContext(context.Background(), name, mode, ch)
140 }
141
142
143
144 func (c *Conn) RestartUnitContext(ctx context.Context, name string, mode string, ch chan<- string) (int, error) {
145 return c.startJob(ctx, ch, "org.freedesktop.systemd1.Manager.RestartUnit", name, mode)
146 }
147
148
149 func (c *Conn) TryRestartUnit(name string, mode string, ch chan<- string) (int, error) {
150 return c.TryRestartUnitContext(context.Background(), name, mode, ch)
151 }
152
153
154
155 func (c *Conn) TryRestartUnitContext(ctx context.Context, name string, mode string, ch chan<- string) (int, error) {
156 return c.startJob(ctx, ch, "org.freedesktop.systemd1.Manager.TryRestartUnit", name, mode)
157 }
158
159
160 func (c *Conn) ReloadOrRestartUnit(name string, mode string, ch chan<- string) (int, error) {
161 return c.ReloadOrRestartUnitContext(context.Background(), name, mode, ch)
162 }
163
164
165
166 func (c *Conn) ReloadOrRestartUnitContext(ctx context.Context, name string, mode string, ch chan<- string) (int, error) {
167 return c.startJob(ctx, ch, "org.freedesktop.systemd1.Manager.ReloadOrRestartUnit", name, mode)
168 }
169
170
171 func (c *Conn) ReloadOrTryRestartUnit(name string, mode string, ch chan<- string) (int, error) {
172 return c.ReloadOrTryRestartUnitContext(context.Background(), name, mode, ch)
173 }
174
175
176
177 func (c *Conn) ReloadOrTryRestartUnitContext(ctx context.Context, name string, mode string, ch chan<- string) (int, error) {
178 return c.startJob(ctx, ch, "org.freedesktop.systemd1.Manager.ReloadOrTryRestartUnit", name, mode)
179 }
180
181
182 func (c *Conn) StartTransientUnit(name string, mode string, properties []Property, ch chan<- string) (int, error) {
183 return c.StartTransientUnitContext(context.Background(), name, mode, properties, ch)
184 }
185
186
187
188
189
190
191 func (c *Conn) StartTransientUnitContext(ctx context.Context, name string, mode string, properties []Property, ch chan<- string) (int, error) {
192 return c.startJob(ctx, ch, "org.freedesktop.systemd1.Manager.StartTransientUnit", name, mode, properties, make([]PropertyCollection, 0))
193 }
194
195
196 func (c *Conn) KillUnit(name string, signal int32) {
197 c.KillUnitContext(context.Background(), name, signal)
198 }
199
200
201
202 func (c *Conn) KillUnitContext(ctx context.Context, name string, signal int32) {
203 c.KillUnitWithTarget(ctx, name, All, signal)
204 }
205
206
207
208 func (c *Conn) KillUnitWithTarget(ctx context.Context, name string, target Who, signal int32) error {
209 return c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.KillUnit", 0, name, string(target), signal).Store()
210 }
211
212
213 func (c *Conn) ResetFailedUnit(name string) error {
214 return c.ResetFailedUnitContext(context.Background(), name)
215 }
216
217
218 func (c *Conn) ResetFailedUnitContext(ctx context.Context, name string) error {
219 return c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.ResetFailedUnit", 0, name).Store()
220 }
221
222
223 func (c *Conn) SystemState() (*Property, error) {
224 return c.SystemStateContext(context.Background())
225 }
226
227
228
229 func (c *Conn) SystemStateContext(ctx context.Context) (*Property, error) {
230 var err error
231 var prop dbus.Variant
232
233 obj := c.sysconn.Object("org.freedesktop.systemd1", "/org/freedesktop/systemd1")
234 err = obj.CallWithContext(ctx, "org.freedesktop.DBus.Properties.Get", 0, "org.freedesktop.systemd1.Manager", "SystemState").Store(&prop)
235 if err != nil {
236 return nil, err
237 }
238
239 return &Property{Name: "SystemState", Value: prop}, nil
240 }
241
242
243 func (c *Conn) getProperties(ctx context.Context, path dbus.ObjectPath, dbusInterface string) (map[string]interface{}, error) {
244 var err error
245 var props map[string]dbus.Variant
246
247 if !path.IsValid() {
248 return nil, fmt.Errorf("invalid unit name: %v", path)
249 }
250
251 obj := c.sysconn.Object("org.freedesktop.systemd1", path)
252 err = obj.CallWithContext(ctx, "org.freedesktop.DBus.Properties.GetAll", 0, dbusInterface).Store(&props)
253 if err != nil {
254 return nil, err
255 }
256
257 out := make(map[string]interface{}, len(props))
258 for k, v := range props {
259 out[k] = v.Value()
260 }
261
262 return out, nil
263 }
264
265
266 func (c *Conn) GetUnitProperties(unit string) (map[string]interface{}, error) {
267 return c.GetUnitPropertiesContext(context.Background(), unit)
268 }
269
270
271
272 func (c *Conn) GetUnitPropertiesContext(ctx context.Context, unit string) (map[string]interface{}, error) {
273 path := unitPath(unit)
274 return c.getProperties(ctx, path, "org.freedesktop.systemd1.Unit")
275 }
276
277
278 func (c *Conn) GetUnitPathProperties(path dbus.ObjectPath) (map[string]interface{}, error) {
279 return c.GetUnitPathPropertiesContext(context.Background(), path)
280 }
281
282
283
284 func (c *Conn) GetUnitPathPropertiesContext(ctx context.Context, path dbus.ObjectPath) (map[string]interface{}, error) {
285 return c.getProperties(ctx, path, "org.freedesktop.systemd1.Unit")
286 }
287
288
289 func (c *Conn) GetAllProperties(unit string) (map[string]interface{}, error) {
290 return c.GetAllPropertiesContext(context.Background(), unit)
291 }
292
293
294
295 func (c *Conn) GetAllPropertiesContext(ctx context.Context, unit string) (map[string]interface{}, error) {
296 path := unitPath(unit)
297 return c.getProperties(ctx, path, "")
298 }
299
300 func (c *Conn) getProperty(ctx context.Context, unit string, dbusInterface string, propertyName string) (*Property, error) {
301 var err error
302 var prop dbus.Variant
303
304 path := unitPath(unit)
305 if !path.IsValid() {
306 return nil, errors.New("invalid unit name: " + unit)
307 }
308
309 obj := c.sysconn.Object("org.freedesktop.systemd1", path)
310 err = obj.CallWithContext(ctx, "org.freedesktop.DBus.Properties.Get", 0, dbusInterface, propertyName).Store(&prop)
311 if err != nil {
312 return nil, err
313 }
314
315 return &Property{Name: propertyName, Value: prop}, nil
316 }
317
318
319 func (c *Conn) GetUnitProperty(unit string, propertyName string) (*Property, error) {
320 return c.GetUnitPropertyContext(context.Background(), unit, propertyName)
321 }
322
323
324
325 func (c *Conn) GetUnitPropertyContext(ctx context.Context, unit string, propertyName string) (*Property, error) {
326 return c.getProperty(ctx, unit, "org.freedesktop.systemd1.Unit", propertyName)
327 }
328
329
330 func (c *Conn) GetServiceProperty(service string, propertyName string) (*Property, error) {
331 return c.GetServicePropertyContext(context.Background(), service, propertyName)
332 }
333
334
335 func (c *Conn) GetServicePropertyContext(ctx context.Context, service string, propertyName string) (*Property, error) {
336 return c.getProperty(ctx, service, "org.freedesktop.systemd1.Service", propertyName)
337 }
338
339
340 func (c *Conn) GetUnitTypeProperties(unit string, unitType string) (map[string]interface{}, error) {
341 return c.GetUnitTypePropertiesContext(context.Background(), unit, unitType)
342 }
343
344
345
346
347 func (c *Conn) GetUnitTypePropertiesContext(ctx context.Context, unit string, unitType string) (map[string]interface{}, error) {
348 path := unitPath(unit)
349 return c.getProperties(ctx, path, "org.freedesktop.systemd1."+unitType)
350 }
351
352
353 func (c *Conn) SetUnitProperties(name string, runtime bool, properties ...Property) error {
354 return c.SetUnitPropertiesContext(context.Background(), name, runtime, properties...)
355 }
356
357
358
359
360
361
362
363
364 func (c *Conn) SetUnitPropertiesContext(ctx context.Context, name string, runtime bool, properties ...Property) error {
365 return c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.SetUnitProperties", 0, name, runtime, properties).Store()
366 }
367
368
369 func (c *Conn) GetUnitTypeProperty(unit string, unitType string, propertyName string) (*Property, error) {
370 return c.GetUnitTypePropertyContext(context.Background(), unit, unitType, propertyName)
371 }
372
373
374
375 func (c *Conn) GetUnitTypePropertyContext(ctx context.Context, unit string, unitType string, propertyName string) (*Property, error) {
376 return c.getProperty(ctx, unit, "org.freedesktop.systemd1."+unitType, propertyName)
377 }
378
379 type UnitStatus struct {
380 Name string
381 Description string
382 LoadState string
383 ActiveState string
384 SubState string
385 Followed string
386 Path dbus.ObjectPath
387 JobId uint32
388 JobType string
389 JobPath dbus.ObjectPath
390 }
391
392 type storeFunc func(retvalues ...interface{}) error
393
394 func (c *Conn) listUnitsInternal(f storeFunc) ([]UnitStatus, error) {
395 result := make([][]interface{}, 0)
396 err := f(&result)
397 if err != nil {
398 return nil, err
399 }
400
401 resultInterface := make([]interface{}, len(result))
402 for i := range result {
403 resultInterface[i] = result[i]
404 }
405
406 status := make([]UnitStatus, len(result))
407 statusInterface := make([]interface{}, len(status))
408 for i := range status {
409 statusInterface[i] = &status[i]
410 }
411
412 err = dbus.Store(resultInterface, statusInterface...)
413 if err != nil {
414 return nil, err
415 }
416
417 return status, nil
418 }
419
420
421
422
423 func (c *Conn) GetUnitByPID(ctx context.Context, pid uint32) (dbus.ObjectPath, error) {
424 var result dbus.ObjectPath
425
426 err := c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.GetUnitByPID", 0, pid).Store(&result)
427
428 return result, err
429 }
430
431
432
433
434 func (c *Conn) GetUnitNameByPID(ctx context.Context, pid uint32) (string, error) {
435 path, err := c.GetUnitByPID(ctx, pid)
436 if err != nil {
437 return "", err
438 }
439
440 return unitName(path), nil
441 }
442
443
444 func (c *Conn) ListUnits() ([]UnitStatus, error) {
445 return c.ListUnitsContext(context.Background())
446 }
447
448
449
450
451
452
453 func (c *Conn) ListUnitsContext(ctx context.Context) ([]UnitStatus, error) {
454 return c.listUnitsInternal(c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.ListUnits", 0).Store)
455 }
456
457
458 func (c *Conn) ListUnitsFiltered(states []string) ([]UnitStatus, error) {
459 return c.ListUnitsFilteredContext(context.Background(), states)
460 }
461
462
463
464 func (c *Conn) ListUnitsFilteredContext(ctx context.Context, states []string) ([]UnitStatus, error) {
465 return c.listUnitsInternal(c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.ListUnitsFiltered", 0, states).Store)
466 }
467
468
469 func (c *Conn) ListUnitsByPatterns(states []string, patterns []string) ([]UnitStatus, error) {
470 return c.ListUnitsByPatternsContext(context.Background(), states, patterns)
471 }
472
473
474
475
476
477 func (c *Conn) ListUnitsByPatternsContext(ctx context.Context, states []string, patterns []string) ([]UnitStatus, error) {
478 return c.listUnitsInternal(c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.ListUnitsByPatterns", 0, states, patterns).Store)
479 }
480
481
482 func (c *Conn) ListUnitsByNames(units []string) ([]UnitStatus, error) {
483 return c.ListUnitsByNamesContext(context.Background(), units)
484 }
485
486
487
488
489
490
491
492 func (c *Conn) ListUnitsByNamesContext(ctx context.Context, units []string) ([]UnitStatus, error) {
493 return c.listUnitsInternal(c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.ListUnitsByNames", 0, units).Store)
494 }
495
496 type UnitFile struct {
497 Path string
498 Type string
499 }
500
501 func (c *Conn) listUnitFilesInternal(f storeFunc) ([]UnitFile, error) {
502 result := make([][]interface{}, 0)
503 err := f(&result)
504 if err != nil {
505 return nil, err
506 }
507
508 resultInterface := make([]interface{}, len(result))
509 for i := range result {
510 resultInterface[i] = result[i]
511 }
512
513 files := make([]UnitFile, len(result))
514 fileInterface := make([]interface{}, len(files))
515 for i := range files {
516 fileInterface[i] = &files[i]
517 }
518
519 err = dbus.Store(resultInterface, fileInterface...)
520 if err != nil {
521 return nil, err
522 }
523
524 return files, nil
525 }
526
527
528 func (c *Conn) ListUnitFiles() ([]UnitFile, error) {
529 return c.ListUnitFilesContext(context.Background())
530 }
531
532
533 func (c *Conn) ListUnitFilesContext(ctx context.Context) ([]UnitFile, error) {
534 return c.listUnitFilesInternal(c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.ListUnitFiles", 0).Store)
535 }
536
537
538 func (c *Conn) ListUnitFilesByPatterns(states []string, patterns []string) ([]UnitFile, error) {
539 return c.ListUnitFilesByPatternsContext(context.Background(), states, patterns)
540 }
541
542
543 func (c *Conn) ListUnitFilesByPatternsContext(ctx context.Context, states []string, patterns []string) ([]UnitFile, error) {
544 return c.listUnitFilesInternal(c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.ListUnitFilesByPatterns", 0, states, patterns).Store)
545 }
546
547 type LinkUnitFileChange EnableUnitFileChange
548
549
550 func (c *Conn) LinkUnitFiles(files []string, runtime bool, force bool) ([]LinkUnitFileChange, error) {
551 return c.LinkUnitFilesContext(context.Background(), files, runtime, force)
552 }
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571 func (c *Conn) LinkUnitFilesContext(ctx context.Context, files []string, runtime bool, force bool) ([]LinkUnitFileChange, error) {
572 result := make([][]interface{}, 0)
573 err := c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.LinkUnitFiles", 0, files, runtime, force).Store(&result)
574 if err != nil {
575 return nil, err
576 }
577
578 resultInterface := make([]interface{}, len(result))
579 for i := range result {
580 resultInterface[i] = result[i]
581 }
582
583 changes := make([]LinkUnitFileChange, len(result))
584 changesInterface := make([]interface{}, len(changes))
585 for i := range changes {
586 changesInterface[i] = &changes[i]
587 }
588
589 err = dbus.Store(resultInterface, changesInterface...)
590 if err != nil {
591 return nil, err
592 }
593
594 return changes, nil
595 }
596
597
598 func (c *Conn) EnableUnitFiles(files []string, runtime bool, force bool) (bool, []EnableUnitFileChange, error) {
599 return c.EnableUnitFilesContext(context.Background(), files, runtime, force)
600 }
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618 func (c *Conn) EnableUnitFilesContext(ctx context.Context, files []string, runtime bool, force bool) (bool, []EnableUnitFileChange, error) {
619 var carries_install_info bool
620
621 result := make([][]interface{}, 0)
622 err := c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.EnableUnitFiles", 0, files, runtime, force).Store(&carries_install_info, &result)
623 if err != nil {
624 return false, nil, err
625 }
626
627 resultInterface := make([]interface{}, len(result))
628 for i := range result {
629 resultInterface[i] = result[i]
630 }
631
632 changes := make([]EnableUnitFileChange, len(result))
633 changesInterface := make([]interface{}, len(changes))
634 for i := range changes {
635 changesInterface[i] = &changes[i]
636 }
637
638 err = dbus.Store(resultInterface, changesInterface...)
639 if err != nil {
640 return false, nil, err
641 }
642
643 return carries_install_info, changes, nil
644 }
645
646 type EnableUnitFileChange struct {
647 Type string
648 Filename string
649 Destination string
650 }
651
652
653 func (c *Conn) DisableUnitFiles(files []string, runtime bool) ([]DisableUnitFileChange, error) {
654 return c.DisableUnitFilesContext(context.Background(), files, runtime)
655 }
656
657
658
659
660
661
662
663
664
665
666
667
668
669 func (c *Conn) DisableUnitFilesContext(ctx context.Context, files []string, runtime bool) ([]DisableUnitFileChange, error) {
670 result := make([][]interface{}, 0)
671 err := c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.DisableUnitFiles", 0, files, runtime).Store(&result)
672 if err != nil {
673 return nil, err
674 }
675
676 resultInterface := make([]interface{}, len(result))
677 for i := range result {
678 resultInterface[i] = result[i]
679 }
680
681 changes := make([]DisableUnitFileChange, len(result))
682 changesInterface := make([]interface{}, len(changes))
683 for i := range changes {
684 changesInterface[i] = &changes[i]
685 }
686
687 err = dbus.Store(resultInterface, changesInterface...)
688 if err != nil {
689 return nil, err
690 }
691
692 return changes, nil
693 }
694
695 type DisableUnitFileChange struct {
696 Type string
697 Filename string
698 Destination string
699 }
700
701
702 func (c *Conn) MaskUnitFiles(files []string, runtime bool, force bool) ([]MaskUnitFileChange, error) {
703 return c.MaskUnitFilesContext(context.Background(), files, runtime, force)
704 }
705
706
707
708
709
710
711
712
713
714
715 func (c *Conn) MaskUnitFilesContext(ctx context.Context, files []string, runtime bool, force bool) ([]MaskUnitFileChange, error) {
716 result := make([][]interface{}, 0)
717 err := c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.MaskUnitFiles", 0, files, runtime, force).Store(&result)
718 if err != nil {
719 return nil, err
720 }
721
722 resultInterface := make([]interface{}, len(result))
723 for i := range result {
724 resultInterface[i] = result[i]
725 }
726
727 changes := make([]MaskUnitFileChange, len(result))
728 changesInterface := make([]interface{}, len(changes))
729 for i := range changes {
730 changesInterface[i] = &changes[i]
731 }
732
733 err = dbus.Store(resultInterface, changesInterface...)
734 if err != nil {
735 return nil, err
736 }
737
738 return changes, nil
739 }
740
741 type MaskUnitFileChange struct {
742 Type string
743 Filename string
744 Destination string
745 }
746
747
748 func (c *Conn) UnmaskUnitFiles(files []string, runtime bool) ([]UnmaskUnitFileChange, error) {
749 return c.UnmaskUnitFilesContext(context.Background(), files, runtime)
750 }
751
752
753
754
755
756
757
758
759 func (c *Conn) UnmaskUnitFilesContext(ctx context.Context, files []string, runtime bool) ([]UnmaskUnitFileChange, error) {
760 result := make([][]interface{}, 0)
761 err := c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.UnmaskUnitFiles", 0, files, runtime).Store(&result)
762 if err != nil {
763 return nil, err
764 }
765
766 resultInterface := make([]interface{}, len(result))
767 for i := range result {
768 resultInterface[i] = result[i]
769 }
770
771 changes := make([]UnmaskUnitFileChange, len(result))
772 changesInterface := make([]interface{}, len(changes))
773 for i := range changes {
774 changesInterface[i] = &changes[i]
775 }
776
777 err = dbus.Store(resultInterface, changesInterface...)
778 if err != nil {
779 return nil, err
780 }
781
782 return changes, nil
783 }
784
785 type UnmaskUnitFileChange struct {
786 Type string
787 Filename string
788 Destination string
789 }
790
791
792 func (c *Conn) Reload() error {
793 return c.ReloadContext(context.Background())
794 }
795
796
797
798 func (c *Conn) ReloadContext(ctx context.Context) error {
799 return c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.Reload", 0).Store()
800 }
801
802 func unitPath(name string) dbus.ObjectPath {
803 return dbus.ObjectPath("/org/freedesktop/systemd1/unit/" + PathBusEscape(name))
804 }
805
806
807 func unitName(dpath dbus.ObjectPath) string {
808 return pathBusUnescape(path.Base(string(dpath)))
809 }
810
811
812 type JobStatus struct {
813 Id uint32
814 Unit string
815 JobType string
816 Status string
817 JobPath dbus.ObjectPath
818 UnitPath dbus.ObjectPath
819 }
820
821
822 func (c *Conn) ListJobs() ([]JobStatus, error) {
823 return c.ListJobsContext(context.Background())
824 }
825
826
827 func (c *Conn) ListJobsContext(ctx context.Context) ([]JobStatus, error) {
828 return c.listJobsInternal(ctx)
829 }
830
831 func (c *Conn) listJobsInternal(ctx context.Context) ([]JobStatus, error) {
832 result := make([][]interface{}, 0)
833 if err := c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.ListJobs", 0).Store(&result); err != nil {
834 return nil, err
835 }
836
837 resultInterface := make([]interface{}, len(result))
838 for i := range result {
839 resultInterface[i] = result[i]
840 }
841
842 status := make([]JobStatus, len(result))
843 statusInterface := make([]interface{}, len(status))
844 for i := range status {
845 statusInterface[i] = &status[i]
846 }
847
848 if err := dbus.Store(resultInterface, statusInterface...); err != nil {
849 return nil, err
850 }
851
852 return status, nil
853 }
854
855
856
857 func (c *Conn) FreezeUnit(ctx context.Context, unit string) error {
858 return c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.FreezeUnit", 0, unit).Store()
859 }
860
861
862 func (c *Conn) ThawUnit(ctx context.Context, unit string) error {
863 return c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.ThawUnit", 0, unit).Store()
864 }
865
View as plain text