Skip to content

Commit 6005fac

Browse files
committed
Reindent all code using latest Xcode
1 parent 809fbad commit 6005fac

File tree

13 files changed

+323
-320
lines changed

13 files changed

+323
-320
lines changed

Sources/SignalHandling/CStructsInSwift/Sigaction.swift

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ public struct Sigaction : Equatable, RawRepresentable {
1010
public static let defaultAction = Sigaction(handler: .defaultHandler)
1111

1212
/**
13-
Check if the given signal is ignored using `sigaction`. */
13+
Check if the given signal is ignored using `sigaction`. */
1414
public static func isSignalIgnored(_ signal: Signal) throws -> Bool {
1515
return try Sigaction(signal: signal).handler == .ignoreHandler
1616
}
1717

1818
/**
19-
Check if the given signal is handled with default action using `sigaction`. */
19+
Check if the given signal is handled with default action using `sigaction`. */
2020
public static func isSignalDefaultAction(_ signal: Signal) throws -> Bool {
2121
return try Sigaction(signal: signal).handler == .defaultHandler
2222
}
@@ -36,32 +36,32 @@ public struct Sigaction : Equatable, RawRepresentable {
3636
}
3737

3838
/**
39-
Create a `Sigaction` from a `sigaction`.
40-
41-
If the handler of the sigaction is `SIG_IGN` or `SIG_DFL`, we check the
42-
`sa_flags` not to contains the `SA_SIGINFO` bit. If they do, we log an error,
43-
as this is invalid. */
39+
Create a `Sigaction` from a `sigaction`.
40+
41+
If the handler of the sigaction is `SIG_IGN` or `SIG_DFL`, we check the
42+
`sa_flags` not to contains the `SA_SIGINFO` bit. If they do, we log an
43+
error, as this is invalid. */
4444
public init(rawValue: sigaction) {
4545
self.mask = Signal.set(from: rawValue.sa_mask)
4646
self.flags = SigactionFlags(rawValue: rawValue.sa_flags)
4747

48-
#if !os(Linux)
48+
#if !os(Linux)
4949
switch OpaquePointer(bitPattern: unsafeBitCast(rawValue.__sigaction_u.__sa_handler, to: Int.self)) {
5050
case OpaquePointer(bitPattern: unsafeBitCast(SIG_IGN, to: Int.self)): self.handler = .ignoreHandler
5151
case OpaquePointer(bitPattern: unsafeBitCast(SIG_DFL, to: Int.self)): self.handler = .defaultHandler
5252
default:
5353
if flags.contains(.siginfo) {self.handler = .posix(rawValue.__sigaction_u.__sa_sigaction)}
5454
else {self.handler = .ansiC(rawValue.__sigaction_u.__sa_handler)}
5555
}
56-
#else
56+
#else
5757
switch OpaquePointer(bitPattern: unsafeBitCast(rawValue.__sigaction_handler.sa_handler, to: Int.self)) {
5858
case OpaquePointer(bitPattern: unsafeBitCast(SIG_IGN, to: Int.self)): self.handler = .ignoreHandler
5959
case OpaquePointer(bitPattern: unsafeBitCast(SIG_DFL, to: Int.self)): self.handler = .defaultHandler
6060
default:
6161
if flags.contains(.siginfo) {self.handler = .posix(rawValue.__sigaction_handler.sa_sigaction)}
6262
else {self.handler = .ansiC(rawValue.__sigaction_handler.sa_handler)}
6363
}
64-
#endif
64+
#endif
6565

6666
if !isValid {
6767
SignalHandlingConfig.logger?.warning("Initialized an invalid Sigaction.")
@@ -85,42 +85,42 @@ public struct Sigaction : Equatable, RawRepresentable {
8585
ret.sa_mask = Signal.sigset(from: mask)
8686
ret.sa_flags = flags.rawValue
8787

88-
#if !os(Linux)
88+
#if !os(Linux)
8989
switch handler {
9090
case .ignoreHandler: ret.__sigaction_u.__sa_handler = SIG_IGN
9191
case .defaultHandler: ret.__sigaction_u.__sa_handler = SIG_DFL
9292
case .ansiC(let h): ret.__sigaction_u.__sa_handler = h
9393
case .posix(let h): ret.__sigaction_u.__sa_sigaction = h
9494
}
95-
#else
95+
#else
9696
switch handler {
9797
case .ignoreHandler: ret.__sigaction_handler.sa_handler = SIG_IGN
9898
case .defaultHandler: ret.__sigaction_handler.sa_handler = SIG_DFL
9999
case .ansiC(let h): ret.__sigaction_handler.sa_handler = h
100100
case .posix(let h): ret.__sigaction_handler.sa_sigaction = h
101101
}
102-
#endif
102+
#endif
103103

104104
return ret
105105
}
106106

107107
/**
108-
Only one check: do the flags **not** contain `siginfo` if handler is either
109-
`.ignoreHandler` or `.defaultHandler`. */
108+
Only one check: do the flags **not** contain `siginfo` if handler is either
109+
`.ignoreHandler` or `.defaultHandler`. */
110110
public var isValid: Bool {
111111
return !flags.contains(.siginfo) || (handler != .ignoreHandler && handler != .defaultHandler)
112112
}
113113

114114
/**
115-
Installs the sigaction and returns the old one if different.
116-
117-
It is impossible for a sigaction handler to be `nil`. If the method returns
118-
`nil`, the previous handler was exactly the same as the one you installed.
119-
Note however the sigaction function is always called in this method.
120-
121-
If `updateUnsigRegistrations` is true (default), If there are delayed
122-
sigactions registered with `SigactionDelayer_Unsig`, these registrations will
123-
be updated and `sigaction` will not be called. */
115+
Installs the sigaction and returns the old one if different.
116+
117+
It is impossible for a sigaction handler to be `nil`. If the method returns
118+
`nil`, the previous handler was exactly the same as the one you installed.
119+
Note however the sigaction function is always called in this method.
120+
121+
If `updateUnsigRegistrations` is true (default), If there are delayed
122+
sigactions registered with `SigactionDelayer_Unsig`, these registrations
123+
will be updated and `sigaction` will not be called. */
124124
@discardableResult
125125
public func install(on signal: Signal, revertIfIgnored: Bool = true, updateUnsigRegistrations: Bool = true) throws -> Sigaction? {
126126
if updateUnsigRegistrations, let oldSigaction = SigactionDelayer_Unsig.updateOriginalSigaction(for: signal, to: self) {

Sources/SignalHandling/CStructsInSwift/SigactionFlag.swift

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,41 @@ import Foundation
66
public struct SigactionFlags : OptionSet {
77

88
/**
9-
If this bit is set when installing a catching function for the `SIGCHLD`
10-
signal, the `SIGCHLD` signal will be generated only when a child process
11-
exits, not when a child process stops. */
9+
If this bit is set when installing a catching function for the `SIGCHLD`
10+
signal, the `SIGCHLD` signal will be generated only when a child process
11+
exits, not when a child process stops. */
1212
public static let noChildStop = SigactionFlags(rawValue: SA_NOCLDSTOP)
1313

1414
/**
15-
If this bit is set when calling `sigaction()` for the `SIGCHLD` signal, the
16-
system will not create zombie processes when children of the calling process
17-
exit. If the calling process subsequently issues a `wait(2)` (or equivalent),
18-
it blocks until all of the calling process’s child processes terminate, and
19-
then returns a value of -1 with errno set to ECHILD. */
15+
If this bit is set when calling `sigaction()` for the `SIGCHLD` signal, the
16+
system will not create zombie processes when children of the calling process
17+
exit. If the calling process subsequently issues a `wait(2)` (or
18+
equivalent), it blocks until all of the calling process’s child processes
19+
terminate, and then returns a value of -1 with errno set to ECHILD. */
2020
public static let noChildWait = SigactionFlags(rawValue: SA_NOCLDWAIT)
2121

2222
/**
23-
If this bit is set, the system will deliver the signal to the process on a
24-
signal stack, specified with `sigaltstack(2)`. */
23+
If this bit is set, the system will deliver the signal to the process on a
24+
signal stack, specified with `sigaltstack(2)`. */
2525
public static let onStack = SigactionFlags(rawValue: SA_ONSTACK)
2626

2727
/**
28-
If this bit is set, further occurrences of the delivered signal are not
29-
masked during the execution of the handler. */
28+
If this bit is set, further occurrences of the delivered signal are not
29+
masked during the execution of the handler. */
3030
public static let noDefer = SigactionFlags(rawValue: SA_NODEFER)
3131

3232
/**
33-
If this bit is set, the handler is reset back to `SIG_DFL` at the moment the
34-
signal is delivered. */
33+
If this bit is set, the handler is reset back to `SIG_DFL` at the moment the
34+
signal is delivered. */
3535
public static let resetHandler = SigactionFlags(rawValue: CInt(SA_RESETHAND) /* On Linux, an UInt32 instead of Int32, so we cast… */)
3636

3737
/** See `sigaction(2)`. */
3838
public static let restart = SigactionFlags(rawValue: SA_RESTART)
3939

4040
/**
41-
If this bit is set, the handler function is assumed to be pointed to by the
42-
`sa_sigaction` member of struct sigaction and should match the matching
43-
prototype. This bit should not be set when assigning `SIG_DFL` or `SIG_IGN`. */
41+
If this bit is set, the handler function is assumed to be pointed to by the
42+
`sa_sigaction` member of struct sigaction and should match the matching
43+
prototype. This bit should not be set when assigning `SIG_DFL` or `SIG_IGN`. */
4444
public static let siginfo = SigactionFlags(rawValue: SA_SIGINFO)
4545

4646
public let rawValue: CInt

Sources/SignalHandling/CStructsInSwift/SigactionHandler.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ import Foundation
33

44

55
/**
6-
A `sigaction` handler.
7-
8-
Two `SigactionHandler`s are equal iif their cases are equal and the handler
9-
they contain point to the same address (if applicable). */
6+
A `sigaction` handler.
7+
8+
Two `SigactionHandler`s are equal iif their cases are equal and the handler
9+
they contain point to the same address (if applicable). */
1010
public enum SigactionHandler : Equatable {
1111

1212
/* The ignore and default handlers are special cases represented respectively
13-
 * by the `SIG_IGN` and `SIG_DFL` values in C.
14-
 * We choose the represent them using a special case in the enum. You should
15-
 * not (though you could) use `.ansiC(SIG_IGN)` (it is not possible with
16-
 * `SIG_DFL` because `SIG_DFL` is optional… and nil).
17-
 * In particular, `.ignoreHandler != .ansiC(SIG_IGN)` */
13+
* by the `SIG_IGN` and `SIG_DFL` values in C.
14+
* We choose the represent them using a special case in the enum. You should
15+
* not (though you could) use `.ansiC(SIG_IGN)` (it is not possible with
16+
* `SIG_DFL` because `SIG_DFL` is optional… and nil).
17+
* In particular, `.ignoreHandler != .ansiC(SIG_IGN)` */
1818
case ignoreHandler
1919
case defaultHandler
2020

@@ -29,8 +29,8 @@ public enum SigactionHandler : Equatable {
2929
case (.ansiC, .ansiC), (.posix, .posix):
3030
return lhs.asOpaquePointer == rhs.asOpaquePointer
3131

32-
/* Using this matching patterns instead of simply default, we force a
33-
 * compilation error in case more cases are added later. */
32+
/* Using this matching patterns instead of simply default, we force
33+
* a compilation error in case more cases are added later. */
3434
case (.ignoreHandler, _), (.defaultHandler, _), (.ansiC, _), (.posix, _):
3535
return false
3636
}

0 commit comments

Comments
 (0)