Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

Commit abe74da

Browse files
committed
feat: Add worker for dhclient (#8)
1 parent 2e77766 commit abe74da

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

pkg/utils/processworker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"syscall"
66
)
77

8-
// ProcessWorker is a worker that manages a process
8+
// ProcessWorker is a worker that manages a process.
99
type ProcessWorker struct {
1010
Instance *exec.Cmd
1111
ScheduledForDeletion bool

pkg/workers/dhclient.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package workers
2+
3+
import (
4+
"github.com/pojntfx/godhcpd/pkg/utils"
5+
"os"
6+
"os/exec"
7+
"syscall"
8+
)
9+
10+
// DHClient is a dhcp client.
11+
type DHClient struct {
12+
utils.ProcessWorker
13+
Device string
14+
BinaryDir string
15+
}
16+
17+
// Start starts the the dhcp client.
18+
func (d *DHClient) Start() error {
19+
d.ScheduledForDeletion = false
20+
21+
command := exec.Command(d.BinaryDir, "-d", "-i", d.Device)
22+
23+
command.Stdout = os.Stdout
24+
command.Stderr = os.Stderr
25+
26+
command.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
27+
28+
d.Instance = command
29+
30+
return command.Start()
31+
}

pkg/workers/dhcpd.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"syscall"
1010
)
1111

12-
// DHCPD is a DHCP server.
12+
// DHCPD is a dhcp server.
1313
type DHCPD struct {
1414
utils.ProcessWorker
1515
Subnets []Subnet
@@ -21,7 +21,7 @@ type DHCPD struct {
2121
leasesFileDir string
2222
}
2323

24-
// Subnet is a DHCP subnet.
24+
// Subnet is a dhcp subnet.
2525
type Subnet struct {
2626
Network string
2727
Netmask string
@@ -34,7 +34,7 @@ type Range struct {
3434
End string
3535
}
3636

37-
// Configure configures the DHCP server.
37+
// Configure configures the dhcp server.
3838
func (d *DHCPD) Configure() error {
3939
var configFileContent string
4040
for _, subnet := range d.Subnets {
@@ -71,7 +71,7 @@ func (d *DHCPD) Configure() error {
7171
return nil
7272
}
7373

74-
// Start starts the the DHCP server.
74+
// Start starts the the dhcp server.
7575
func (d *DHCPD) Start() error {
7676
d.ScheduledForDeletion = false
7777

@@ -87,7 +87,7 @@ func (d *DHCPD) Start() error {
8787
return command.Start()
8888
}
8989

90-
// Cleanup deletes the state of the DHCP server.
90+
// Cleanup deletes the state of the dhcp server.
9191
func (d *DHCPD) Cleanup() error {
9292
return os.RemoveAll(d.StateDir)
9393
}

0 commit comments

Comments
 (0)