Optionally typechecked StateMachines
Many things can be modelled as finite state machines. Particularly things where you’d naturally use “state” in the name e.g. the current state of an order, or delivery status. We often model these as enums.
enum OrderStatus {
Pending,
CheckingOut,
Purchased,
Shipped,
Cancelled,
Delivered,
Failed,
Refunded
}
Enums are great for restricting our order status to only valid states. However, usually there are only certain transitions that are valid. We can’t go from Delivered to Failed. Nor would we go straight from Pending to Delivered. Maybe we can transition from Purchased to either Shipped or Cancelled.
Using enum values we cannot restrict to the transitions to only those that we desire. It would be nice to also let the compiler help us out by not letting us choose invalid transitions in our code.
We can, however, achieve this if we use a class hierarchy to represent our states instead, and it can still be fairly concise. There are other reasons for using regular classes, they allow us to store and even capture state from the surrounding context.
Here’s a way we could model the above enum as a class heirarchy with the valid transitions.
interface OrderStatus extends State {}
static class Pending implements OrderStatus, BiTransitionTo {}
static class CheckingOut implements OrderStatus, BiTransitionTo {}
static class Purchased implements OrderStatus, BiTransitionTo {}
static class Shipped implements OrderStatus, BiTransitionTo {}
static class Delivered implements OrderStatus, TransitionTo {}
static class Cancelled implements OrderStatus {}
static class Failed implements OrderStatus {}
static class Refunded implements OrderStatus {}
We’ve declared an OrderStatus interface and then created implementations of OrderStatus for each valid state. We’ve then encoded the valid transitions as other interface implementations. There’s a TransitionTo<State> and BiTransitionTo<State1,State2>, or TriTransitionTo<State1,State2,State3> depending on the number of valid transitions from that state. We need differently named interfaces for different numbers of transitions because Java doesn’t support variance on the number of generic type parameters.
Compile-time checking valid transitions
Now we can create the TransitionTo/BiTransitionTo interfaces, which can give us the functionality to transition to a new state (but only if it is valid)
We might imagine an api like this where we can choose which state to transition to
new Pending()
.transitionTo(CheckingOut.class)
.transitionTo(Purchased.class)
.transitionTo(Refunded.class) // <-- can we make this line fail to compile?
This turns out to be a little tricky, but not impossible, due to type erasure.
Let's try to implement BiTransitionTo interface with the two valid transition.
public interface BiTransitionTo {
default T transitionTo(Class type) { ... }
default U transitionTo(Class type) { ... }
}
Both of these transitionTo methods have the same erasure. So we can't do it quite like this. However, if we can encourage the consumer of our API to pass a lambda, there is a way to work around this same erasure problem.
So how about this API, where instead of passing class literals we pass constructor references. It looks similarly clean, but constructor references are basically lambdas so we can avoid type erasure.
new Pending()
.transition(CheckingOut::new)
.transition(Purchased::new)
.transition(Refunded::new) // <-- Now we can make this fail to compile

In order to make this work the trick is to create a new interface type for each valid transition within our BiTransitionTo interface
public interface BiTransitionTo {
interface OneTransition extends Supplier { }
default T transition(OneTransition constructor) { ... }
interface TwoTransition extends Supplier { }
default U transition(TwoTransition constructor) { ... }
}
Supplier<T> is a functional interface in the java.util.function that is equivalent to a no-args constructor reference. By creating two interfaces that extend this we can overload the transition() method twice, allowing both methods to be passed a constructor reference without the two methods having the same erasure.
Runtime checking
Sometimes we might not be able to know at compile-time what state our statemachine is in. Perhaps a Customer has a field of type OrderStatus that we serialize to a database. We would need to be able to try a transition at runtime, and fail in some manner if the transition is not valid.
This is also possible using the TransitionTo<NewState> approach outlined above. Since supertype parameters are available at runtime, we can implement a tryTransition() method that uses reflection to check which transitions are permitted.
First we'll need a way of finding the valid transition types. We'll add it to our State base interface.
default List> validTransitionTypes() {
return asList(getClass().getGenericInterfaces())
.stream()
.filter(type -> type instanceof ParameterizedType)
.map(type -> (ParameterizedType) type)
.filter(TransitionTo::isTransition)
.flatMap(type -> asList(type.getActualTypeArguments()).stream())
.map(type -> (Class>) type)
.collect(toList());
}
Note the isTransition filter. Since we have multiple transition interfaces - TransitionTo<T>, BiTransitionTo<T,U>, TriTransitionTo<T,U,V> etc, we need a way of marking them as all specifying transitions. I've used an annotation
@Retention(RUNTIME)
@Target(ElementType.TYPE)
public @interface Transition {
}
static boolean isTransition(ParameterizedType type) {
Class> cls = (Class>)type.getRawType();
return cls.getAnnotationsByType(Transition.class).length > 0;
}
@Transition
public interface TriTransitionTo...
Once we have validTransitionTypes() we can find which transitions are valid at runtime.
static class Pending implements OrderStatus, BiTransitionTo {}
@Test
public void finding_valid_transitions_at_runtime() {
Pending pending = new Pending();
assertEquals(
asList(CheckingOut.class, Cancelled.class),
pending.validTransitionTypes()
);
}
Now that we have the valid types, tryTransition() needs to check whether the requested transition is to one of those types.
This is a little tricky, but since we're passing a lambda we make it a lambda-type-token and use reflection to find the type parameter of the lambda.
Our implementation then looks something like
interface NextState extends Supplier, MethodFinder {
default Class type() {
return (Class) getContainingClass();
}
}
default T tryTransition(NextState desired) {
if (validTransitionTypes.contains(desired.type())) {
return desired.get();
}
throw new IllegalStateTransitionException();
}
We can make it a bit nicer by allowing the caller to specify the exception to throw on error, like an Optional's orElseThrow. We can also allow the caller to ignore failed transitions.
@Test
public void runtime_checked_transition() {
OrderStatus state = new Pending();
assertTrue(state instanceof Pending);
state = state
.tryTransition(CheckingOut::new)
.unchecked();
assertTrue(state instanceof CheckingOut);
}
Since we've transitioned into a known state (or thrown an exception) with tryTransition we could then chain compile-time checked transitions on the end.
@Test
public void runtime_checked_transition() {
OrderStatus state = new Pending();
assertTrue(state instanceof Pending);
state = state
.tryTransition(CheckingOut::new)
.unchecked()
.transition(Purchased::new); // This will be permitted if the tryTransition succeeds.
assertTrue(state instanceof CheckingOut);
}
We can even let people ignore transition failures if they wish, just by catching the exception and returning the original value.
@Test
public void runtime_checked_transition_ignoring_failure() {
OrderStatus state = new Pending();
assertTrue(state instanceof Pending);
state = state
.tryTransition(Refunded::new)
.ignoreIfInvalid();
assertFalse(state instanceof Refunded);
assertTrue(state instanceof Pending);
}
Adding Behaviour
Since our states are classes, we can add behaviour to them.
For instance we could add a notifyProgress() method to our OrderStatus, with different implementations in each state.
interface OrderStatus extends State {
default void notifyProgress(Customer customer, EmailSender sender) {}
}
static class Purchased implements OrderStatus, BiTransitionTo {
public void notifyProgress(Customer customer, EmailSender emailSender) {
emailSender.sendEmail("fulfillment@mycompany.com", "Customer order pending");
emailSender.sendEmail(customer.email(), "Your order is on its way");
}
}
...
OrderStatus status = new Pending();
status.notifyProgress(customer, sender); // Does nothing
status = status
.tryTransition(CheckingOut::new)
.unchecked()
.transition(Purchased::new);
status.notifyProgress(customer, sender) ; // sends emails
Then we can call notifyProgress on any OrderStatus instance and it will notify differently depending on which implementation is active.
Internal Transitions
One of the ways to make most use of the typechecked transitions is to have the transitions internally within the state. e.g. in a state machine for the Regex "A+B" the A state can transition either
- Back to A
- To B
- To a match failure state
If we do this we can make them typechecked even though we don't know what the string we're matching in advance is.
static class A implements APlusB, TriTransitionTo {
public APlusB match(String s) {
if (s.length() < 1) return transition(NoMatch::new);
if (s.charAt(0) == 'A') return transition(A::new).match(s.substring(1));
if (s.charAt(0) == 'B') return transition(B::new).match(s.substring(1));
return transition(NoMatch::new);
}
}
Capturing State
If we use non-static classes we could also capture state from the enclosing class. Supposing these OrderStatuses are contained within an Order class that already has an EmailSender available, we'd no longer need to pass in the emailSender and the customer to the notifyProgress() method.
class Order {
EmailSender emailSender;
Customer customer;
class Purchased implements OrderStatus, BiTransitionTo {
public void notifyProgress() {
emailSender.sendEmail("fulfillment@mycompany.com", "Customer order pending");
emailSender.sendEmail(customer.email(), "Your order is on its way");
}
}
}
Guards
Another feature we might want is the ability to execute some code before transitioning into a new state or after transitioning into a new state. This is something we can add to our base State interface. Let's add two methods beforeTransition() and afterTransition()
interface State {
default void afterTransition(T from) {}
default void beforeTransition(T to) {}
}
We can then update our transition implementation to invoke these guard methods before and after a transition occurs.
We could use this to log all transitions into the Failure state.
class Failed implements OrderStatus {
@Override
public void afterTransition(OrderStatus from) {
failureLog.warning("Oh bother! failed from " + from.getClass().getSimpleName());
}
}
We could also combine state capturing and guard methods to build a stateful-state machine that updates its state on transition instead of just returning the new state. Here's an example where we use a guard method to mutate the state of lightSwitch after each transition.
class LightExample {
Switch lightSwitch = new Off();
public class Switch implements State {
@Override
public void afterTransition(Switch from) {
LightExample.this.lightSwitch = Switch.this;
}
}
public class On extends Switch implements TransitionTo {}
public class Off extends Switch implements TransitionTo {}
@Test
public void stateful_switch() {
assertTrue(lightSwitch instanceof Off);
lightSwitch.tryTransition(On::new).ignoreIfInvalid();
assertTrue(lightSwitch instanceof On);
lightSwitch.tryTransition(Off::new).ignoreIfInvalid();
assertTrue(lightSwitch instanceof Off);
}
}
Show me the code
The code is on github if you'd like to play with it/see full executable examples
KIELUX / 13. Kieler Open Source und Linux Tage
Am 18. + 19. September 2015 (Freitag + Samstag) findet in Kiel die 13. Kieler Open Source und Linux Tage statt. Der Eintritt ist frei. Diesmal ist openSUSE zum ersten Mal in Kiel dabei und erobert nun Schleswig-Holstein – das Land der Horizonte bzw. der echte Norden. Dem Besucher werden interessante Ausstellungen und ein umfangreiches Programm an Vorträgen wie auch Workshops angeboten. Es finden wieder LPI-Prüfungen (Linux Essentials, LPIC-1, LPIC-2, LPIC 3, Univention UVCP) statt.
Am openSUSE-Stand kann jeder Besucher die openSUSE-Distribution einmal Live ausprobieren und sich vom openSUSE-Team beraten lassen. Außerdem werde ich einen Vortrag zu „openSUSE für den täglichen Einsatz“ halten und richtet sich an Linux-Einsteiger oder Umsteiger. Danach werde ich ein Workshop „openSUSE Installationsparty“ leiten, in dem man unter Anleitung openSUSE direkt auf dem eigenen Notebook installiert und bekommt auch ein paar Tipps und Tricks im Umgang mit openSUSE oben drauf. openSUSE-Installationsmedien (USB-Sticks / DVDs) werden kostenfrei zur Verfügung gestellt und können mitgenommen werden. Wer am Workshop teilnehmen möchte, sollte sich besser mit der Anmeldung beeilen. Da nur maximal 10 Plätze reserviert werden können.
Folgende Aussteller sind vor Ort (alphabetisch):
- bytemine (Webseite)
- CAcert (Webseite)
- ChaosKueste (Webseite)
- DiWiSH (Webseite)
- Freifunk Community Kiel (Webseite)
- FSFE (Webseite)
- goos-habermann.de (in der Linux Lounge) (Webseite)
- invis-Server (Webseite)
- Kubuntu (Webseite)
- Linux Lounge (Webseite)
- NetKnights GmbH (Webseite)
- NetUSE AG (Webseite)
- openSUSE (Webseite)
- Reds.io by Flowy Apps (Webseite)
- TML Messaging Suite (Webseite)
- Toppoint (Webseite)
- Zarafa (Webseite)
Quelle: Aussteller auf den Kieler Linuxtagen
Ein Auszug aus dem Programm:
- Das Internet Spiel (Sven Guckes / Beschreibung)
- Work-Life-Revenue Balance als OSS Unternehmen (Felix Kronlage / Beschreibung)
- Reds.io – ein Framework für mehr Privatsphäre in der Cloud (Torben Haase / Beschreibung)
- So fern und doch so nah, nutzen der priv. Cloud mittels SSH (Marek Walther / Beschreibung)
- Effiziente Lösungsstrategien für IT-Probleme (Hauke Goos-Habermann / Beschreibung)
- Der Mailer Mutt (Sven Guckes / Beschreibung)
- Einfach und sicher: OpenVPN mit 2 Faktor Authentisierung auf UCS (Felix Kronlage / Beschreibung)
- 3D-Druck Verfahren und ihre Vor- und Nachteile (Jan-Tarek Butt / Beschreibung)
- Die eigene Cloud mit Seafile (Marek Walther / Beschreibung)
- openSUSE für den täglichen Einsatz (Sebastian Siebert / Beschreibung)
- invis-Server AD – Small Business für kleine Unternehmen (Stefan Schäfer / Beschreibung)
- Flexibles Storage-Management unter Linux mit openATTIC (Lenz Grimmer / Beschreibung)
- Rust – Einstieg in eine neue Programmiersprache (Felix Kronlage / Beschreibung)
- Zentrales Log-Management mit Graylog (Bernd Ahlers / Beschreibung)
- Freifunk 2015 (Freifunk Community Kiel / Beschreibung)
- 1.000.000 Gründe, Linux zu benutzen (Monika Eggers / Beschreibung)
- Ubuntu in Touch (Torsten Franz / Beschreibung)
- FreeYourAndroid – Freie Software auf Android-Geräten (Dominic Hopf / Beschreibung)
- 3D-Scan und Virtualisierungsverfahren (Jan-Tarek Butt / Beschreibung)
- Fortschritt, Pfusch und Betrug – Bemerkung zu IT-Themen (Uwe Grigat / Beschreibung)
Quelle: Programm der Kieler Open Source und Linux Tage 2015
Ein Auszug der angebotenen Workshops:
- Puppet, aller Anfang ist leicht! (Tim Schmeling / Beschreibung)
- Inkscape für Fortgeschrittene 2015 (Samuel Albrecht / Beschreibung)
- Das eigene Zwei-Faktor-System mit privacyIDEA (Cornelius Kölbel / Beschreibung)
- Mutt+GPG (Sven Guckes / Beschreibung)
- Web-Security Workshop (Timo Pagel / Beschreibung)
- IT-Probleme selber lösen (Hauke Goos-Habermann / Beschreibung)
- openSUSE Installationsparty – Workshop (Sebastian Siebert / Beschreibung)
- Fotos bearbeiten mit Gimp für Einsteiger (ggf. mit Fototour) (Frank Bartels / Beschreibung)
- Ausgabe der bestellten RasPis und Zusammenbau (Hauke Goos-Habermann / Beschreibung)
- Workshop: Mail doch selber – Einrichten eines Mailservers (Frank Agerholm / Beschreibung)
- Raspberry Pi mit Kodi als Mediacenter (Helge Haacke / Beschreibung)
- FreeYourAndroid – Workshop (Dominic Hopf / Beschreibung)
- Inkscape für Entdecker (Maren Hachmann / Beschreibung)
- Cloudlösung SeaFile auf dem Raspberry Pi einrichten (Marek Walther / Beschreibung)
- Bildbearbeitung mit GIMP für Fortgeschrittene 2015 (Samuel Albrecht / Beschreibung)
- Was ist Datenschutz? (Martin Rost / Beschreibung)
Quelle: Programm (Workshop) der Kieler Open Source und Linux Tage 2015
Öffnungszeiten
- 18.09.2015 von 10:00 – 18:00 Uhr
- 19.09.2015 von 10:00 – 17:00 Uhr
Veranstaltungsort
Kieler Linux Initiative
c/o Kitz – Kieler Innovations- und Technologiezentrum
Schauenburgerstr. 116
24118 Kiel
Link: Anfahrtsplan
Eintrittpreis: frei
Zu guter Letzt: Bitte weitersagen. ![]()
HTML in Java
Another use of lambda parameter reflection could be to write html inline in Java. It allows us to create builders like this, in Java, where we’d previously have to use a language like Kotlin and a library like Kara.
String doc =
html(
head(
meta(charset -> "utf-8"),
link(rel->stylesheet, type->css, href->"/my.css"),
script(type->javascript, src -> "/some.js")
),
body(
h1("Hello World", style->"font-size:200%;"),
article(
p("Here is an interesting paragraph"),
p(
"And another",
small("small")
),
ul(
li("An"),
li("unordered"),
li("list")
)
)
)
).asString();
Which generates html like
Hello World
Here is an interesting paragraph
And anothersmall
- An
- unordered
- list
Code Generation
Why would you do this? Well we could do code generation. e.g. we can programmatically generate paragraphs.
body(
asList("one","two","three")
.stream()
.map(number -> "Paragraph " + number)
.map(content -> p(content))
)
Help from the Type System
We can also use the Java type system to help us write valid code.
It will be a compile time error to specify an invalid attribute for link rel.

It’s a compile time error to omit a mandatory tag

It’s also a compile time error to have a body tag inside a p tag, because body is not phrasing content.

We can also ensure that image sizes are in pixels
![]()
Safety
We can also help reduce injection attacks when inserting content from users into our markup, by having the DSL html-encoding any content passed in.
e.g.
assertEquals(
"<script src="attack.js"></script>
",
p("").asString()
);
How does it work?
See this previous blogpost that shows how to get lambda parameter names with reflection. This allows us to specify the key value pairs for html attributes quite cleanly.
I’ve created an Attribute
public interface Attribute extends NamedValue {
default String asString() {
return name() + "=\"" + value()+"\"";
}
}
For the tags themselves we declare an interface per tag, with a heirarchy to allow certain tags in certain contexts. For example Small is PhrasingContent and can be inside a P tag.
public interface Small extends PhrasingContent {
default Small small(String content) {
return () -> tag("small", content);
}
}
To make it easy to have all the tag names available in the context without having to static import lots of things, we can create a “mixin” interface that combines all the tags.
public interface HtmlDsl extends
Html,
Head,
Body,
Link,
Meta,
P,
Script,
H1,
Li,
Ul,
Article,
Small,
Img
...
Then where we want to write html we just make our class implement HtmlDsl (Or we could staticly import the methods instead.
We can place restrictions on which tags are valid using overloaded methods for the tag names. e.g. HTML
public interface Html extends NoAttributes {
default Html html(Head head, Body body) {
...
and restrict the types of attributes using enums or other wrapper types. Here Img tag can only have measurements in pixels
public interface Img extends NoChildren {
default Img img(Attribute src, Attribute dim1, Attribute dim2) {
...
All the code is available on github to play with. Have a look at this test for executable examples. n.b. it’s just a proof of concept at this point. Only sufficient code exists to illustrate the examples in this blog post.
What other creative uses can you find for parameter reflection?
Oh hell! It’s open source project
This was supposed to be survival guide to open source and free software world but I realized I’m not that good citizen of open source world that I can give any advises to others. What I’m giving are hint’s what I have learn along the years. So why I’m not very good open source citizen? I read several projects mail lists but only topics that I like and make contributions but not with rage but when I feel like it. I answer few mails that I receive about open source in limited time frame that I have (which sometimes can be too long) and use many projects with out giving anything back. I prefer license to steal and freedom as value not as in beer.
What is license for?
Wear your tin-hats and make securing spells because here we go. In modern world everything is for sale and everything you can image will be stolen and in-incorporated in nuclear bomb or used in mass destruction of human beings. This ain’t new feature in human society. For example fire have been probably one man thing for long time (and I can just imagine how many jokes you can make about that poor fellow and that even poorer soul that first roasted something) after a while it widespread all over the world and same goes with wheel. They were invented somewhere and someone took them in use without giving a dime to the inventor. Is it fair? No it’s not. Bit harsh and unfair to this original guy but again this is how ball is played.
What this is related to licensing and what is the big deal of open source and free software anyway if this the Status Quo? What are the licenses for? Believe or not they are important agreements! It’s not secret that most of the Github repositories are still without proper license. That is why they launch: http://choosealicense.com/. Take time and study a bit or if you don’t have a time I’ll tell how I see things.
Free software
There is Free Software movement which is constructed around GNU project and FSF (Free Software Foundation). Most significant person in Free software is Richard Stallman (Yes that hansom guy with a beard) . If you want more history please read it from FSF site they know it more better than me. Main principals in Free software are Freedom, Freedom to share and make sure that everyone else have that freedom also.
Free Software licenses are commonly known as Copyleft licenses and most know is Gnu Public license (Actually version 3.0 ain’t that popular). All these licenses share a same thing. You will always have 4 freedoms:
- Freedom 0 – the freedom to use the work
- Freedom 1 – the freedom to study the work
- Freedom 2 – the freedom to copy and share the work with others
- Freedom 3 – the freedom to modify the work, and the freedom to distribute modified and therefore derivative works.
What this means (and I’m not a lawyer so don’t blame me if you get sued) is that you can make your changes to code, used it in nuclear bomb but if you release your bomb to big public (or make it available only in machine readable form) you must release also the code changes you have made to original code. There is eternal fight do these changes have to be delivered to upstream project and do they have to be suitable to attach into original code base.
This why every distribution is releasing their source packages (which ain’t bad thing at all) because GPL demands it. Copyleft tries to make sure you will get source code of binary if you demand it but it can be made available only for those who demand it and even in printed out form as A4 papers.
Copyleft there different opinions how these license articles really apply and there is plenty of violations like Allwinner. Still most of them a settled out of the court. One of the biggest GPL (which wasn’t about GPL license at all) that get in the court was (or is it still?) Linux kernel vs SCO. It was only possible because code was freely available and everyone could study it.
Because you didn’t read the anything above. Remember one thing Copyleft is VERY restrictive license. If you are using some library which is using Copyleft license of any form and you doing in-house development make sure you apply license demands before releasing your work or it could get real nasty. Main thing is: you have the right to use the source but same time you have to provide everyone else the same rights and no this doesn’t mean you have to have version control or bug tracker.
Puppy projects: Linux, Libreoffice, Blender and GIMP
Open source
Open Source licenses are widespread and there is plenty more of them than there is Copyleft licenses. How they compare Copyleft? Open Soure licenses tend to give you all rights so they are more liberal. Most popular licenses are MIT, Apache License 2.0 and BSD license. Why they are popular? It’s because they are simple and all these three gives you right to do what ever you want with these files and choose you want to contribute back. If you choose some not popular license you have to make sure you are compatible with GPL without that there is no game.
Why even have license then if you don’t care what people do with your stuff? Choosing liberate Open Source license is not letting everyone ‘steal’ your work it’s about making sure that they know what they can do with it and you are the owner of the rights. Project without any license or release as Public domain is most dangerous ever because you don’t know is this some kind of bomb project that author is waiting to spread and then he or she is making demand on court with statement ‘hey I have this code on Internet and this my new EULA! GIVE ME YOU €€€ (or $$$ sometimes £££) YOU FEALTY ROBBERS!’. These licenses most cases tell what kind of warranty you have and every time it’s next to nothing.
Why then choose Open Source license and not the Free Software? It’s about the attitude: Freedom makes freedom happen. With Free Software you are forced to be free and with Open Source you can choose what is your freedom level and of course you need something to fight about.
Puppy projects: Docker, FreeBSD, Apache HTTP server
What about something else that is not code
Back in days creative works was a weak spot of licensing. Free Software and Open Source license are very fitting to code but they are not very well fitting to creative work. This is why Creative Commons (commonly known as CC) was created. There is suitable licenses for sharing you images, writings or what ever. They have Copyleft style licenses and then more liberal ones. Take you time and find what fits to your project.
Lengthy post but nothing much to said
I think I’ll rest my case here. Next time I think I’ll post about contributing code and remember these are my OWN observations. If they are incorrect please let me know or if you hate me because I like Systemd and liberal licenses you can tell that too. Remember it’s your project and you can choose any license in the world you like.
Удаленная сетевая консоль ядра Linux
Полное описание сетевой консоли находится в документации ядра. Для настройки достаточно добавить в modprobe.d/99-local.conf:
options netconsole netconsole=@/,514@192.168.10.7/00:0C:29:F3:92:97Здесь, 514 - номер UDP порта, 192.168.10.7 - IP удаленного хоста куда будет отсылаться информация, 00:0C:29:F3:92:97 - его MAC адрес, если его не указать явно то будет использоваться широковещательный адрес FF:FF:FF:FF:FF:FF, что может затруднить передачу информации в зависимости от настроек сетевого оборудования.
И загрузить модуль netconsole или, по желанию, поставить его на автозагрузку при старте системы.
После загрузки модуля netconsole, сетевая консоль начинает немедленно функционировать, а в системном журнале можно увидеть примерно следующее:
May 1 18:57:51 192.168.10.4 kernel: [162255.522603] netconsole: local port 6665 May 1 18:57:51 192.168.10.4 kernel: [162255.522673] netconsole: local IP 0.0.0.0 May 1 18:57:51 192.168.10.4 kernel: [162255.522710] netconsole: interface eth0 May 1 18:57:51 192.168.10.4 kernel: [162255.522746] netconsole: remote port 514 May 1 18:57:51 192.168.10.4 kernel: [162255.522784] netconsole: remote IP 192.168.10.7 May 1 18:57:51 192.168.10.4 kernel: [162255.522826] netconsole: remote ethernet address 00:0c:29:f3:92:97 May 1 18:57:51 192.168.10.4 kernel: [162255.522881] netconsole: local IP 192.168.10.4 May 1 18:57:51 192.168.10.4 kernel: [162255.523032] console [netcon0] enabled May 1 18:57:51 192.168.10.4 kernel: [162255.523349] netconsole: network logging started
Данные приходят в самом простом текстовом виде и их можно читать самым простым способом:
netcat -u -l 514Если у нас в наличии есть syslog-ng — можно использовать его следующим образом:
source s_remote_udp {
network(transport("udp") ip(0.0.0.0) port(514));
};
filter f_remote_remhost {
netmask(192.168.10.4);
};
destination d_remote_remhost {
file("/var/log/remote/remhost.log");
};
log {
source(s_remote_udp);
filter(f_remote_remhost);
destination(d_remote_remhost);
};Проверить, что всё работает можно следующим образом:
echo '<7>Hello world!' > /dev/kmsg dmesg -n 8Сообщение должно появиться в журнале и быть передано по сети на удаленный хост.
Удаленная отладка ядра Linux
Опции конфигурации ядра должны быть такими:
CONFIG_KGDB=y CONFIG_KGDB_SERIAL_CONSOLE=yКроме того, драйвер последовательного порта должен быть включен в состояние Y.
Далее нам понадобятся отладочные символы и исходные коды ядра, которые находятся в пакетах -debuginfo и -debugsource. Скорее всего, архитектуры удаленной и локальной системы не будут совпадать, так как особенно часто ядро Linux не работает на архитектуре armv7l, поэтому просто распакуем данные следующим образом:
> rpm2cpio kernel-default-base-debuginfo-4.2.rc4-1.1.gaf243bc.armv7hl.rpm | cpio -id > rpm2cpio kernel-default-debuginfo-4.2.rc4-1.1.gaf243bc.armv7hl.rpm | cpio -id > rpm2cpio kernel-default-debugsource-4.2.rc4-1.1.gaf243bc.armv7hl.rpm | cpio -idВ текущей директории будет создана поддиректория /usr содержащая отладочные символы и исходные коды в стандартной иерархии. Кроме того, нам понадобятся сами бинарные файлы ядра:
> rpm2cpio kernel-default-base-4.2.rc4-1.1.gaf243bc.armv7hl.rpm | cpio -id > rpm2cpio kernel-default-4.2.rc4-1.1.gaf243bc.armv7hl.rpm | cpio -id
Далее, следует подключить последовательный порт, и открыть удаленную консоль следующим, например, образом:
> screen /dev/ttyUSB0 115200и начать загрузку целевого устройства. Для активации механизма kgdb потребуется добавить параметры командной строки ядра в загрузчике:
U-Boot# setenv append "kgdboc=ttyO0,115200 kgdbwait" U-Boot# boot
Если все пойдет правильно, то загрузка ядра остановится после примерно следующих строк:
[ 3.753423] 44e09000.serial: ttyO0 at MMIO 0x44e09000 (irq = 154, base_baud = 3000000) is a OMAP UART0 [ 4.497783] console [ttyO0] enabled [ 4.502387] STMicroelectronics ASC driver initialized [ 4.507960] KGDB: Registered I/O driver kgdboc [ 4.512673] KGDB: Waiting for connection from remote gdb... Entering kdb (current=0xdb0b3480, pid 1) on processor 0 due to Keyboard Entry [0]kdb>kdb ождает ввода команд, среди прочего доступна команда help, выводящая список базовых команд. На этом консоль можно закрыть: Ctrl-A :quit и открыть отладчик gdb.
Для начала установим пути к отладочным символам и исходным кодам и загрузим объектный файл ядра целевой системы (внимание, сначала этот файл нужно будет распаковать командой gz).
(gdb) set debug-file-directory /tmp/dbg/usr/lib/debug (gdb) directory /tmp/dbg/usr/src/debug/kernel-default-4.2.rc4/linux-4.2-rc4/linux-obj (gdb) file /tmp/dbg/boot/vmlinux-4.2.0-rc4-1.gaf243bc-default Reading symbols from /tmp/dbg/boot/vmlinux-4.2.0-rc4-1.gaf243bc-default...Reading symbols from /tmp/dbg/usr/lib/debug/boot/vmlinux-4.2.0-rc4-1.gaf243bc-default.debug...done. done.После этого нужно подключиться к целевой системе:
(gdb) target remote /dev/ttyUSB0 Remote debugging using /dev/ttyUSB0 0xc031dc08 in arch_kgdb_breakpoint () at ../arch/arm/include/asm/outercache.h:142
Далее можно использовать отладчик как обычно. Через команду monitor доступны все команды из консоли kdb, среди них есть достаточно полезные, например dmesg или lsmod:
(gdb) monitor lsmod Module Size modstruct Used by musb_am335x 1431 0xbf000278 1 (Loading) 0xbf000000 [ ]Обратите внимание, что команда lsmod любезно нам показывает адрес 0xbf000000, куда в памяти загружен модуль musb_am335x. Этот адрес нужен чтобы отлаживать код из модуля:
(gdb) add-symbol-file /tmp/dbg/lib/modules/4.2.0-rc4-1.gaf243bc-default/kernel/drivers/usb/musb/musb_am335x.ko 0xbf000000
Akademy 2015
I am very late with this, but I still wanted to write a few words about Akademy 2015.
First of all: It was an awesome conference! Meeting all the great people involved with KDE and seeing who I am working with (as in: face to face, not via email) was awesome. We had some very interesting discussions on a wide variety of topics, and also enjoyed quite some beer together. Particularly important to me was of course talking to Daniel Vrátil who is working on XdgApp, and Aleix Pol of Muon Discover fame.
Also meeting with the other Kubuntu members was awesome – I haven’t seen some of them for about 3 years, and also met many cool people for the first time.
My talk on AppStream/Limba went well, except that I got slightly confused by the timer showing that I had only 2 minutes left, after I had just completed the first half of my talk. It turned out that the timer was wrong 
Another really nice aspect was to be able to get an insight into areas where I am usually not involved with, like visual design. It was really interesting to learn about the great work others are doing and to talk to people about their work – and I also managed to scratch an itch in the Systemsettings application, where three categories had shown the same icon. Now Systemsettings looks like it is supposed to be, finally 
The only thing I could maybe complain about was the weather, which was more Scotland/Wales like than Spanish – but that didn’t stop us at all, not even at the social event outside. So I actually don’t complain 
We also managed to discuss some new technical stuff, like AppStream for Kubuntu, and plenty of other things that I’ll write about in a separate blog post.
Generally, I got so many new impressions from this year’s Akademy, that I could write a 10-pages long blogpost about it while still having to leave out things.
Kudos to the organizers of this Akademy, you did a fantastic job! I also want to thank the Ubuntu community for funding my trip, and the Kubuntu community for pushing me a little to attend :-).
KDE is a great community with people driving the development of Free Software forward. The diversity of people, projects and ideas in KDE is a pleasure, and I am very happy to be part of this community.
KDE Applications 15.08 RC for openSUSE
KDE has recently released the newest Release Candidate of the Applications 15.08 release. Among the new features and changes of this release, there is a technology preview of the new KF5-based KDE PIM suite (including reworked, faster Akonadi internals), new applications ported to KF5 (the most notable ones being Dolphin and Ark). After some consideration and thinking on how to allow users to test this release without affecting their setups too much, the openSUSE community KDE team is happy to bring this latest RC to openSUSE Tumbleweed and openSUSE 13.21.
To install this new release, add the KDE:Applications repository either using YaST or zypper. One special mention is the PIM suite: as upstream KDE labels it as a technology preview, we decided to allow installation only with an explicit choice of the user. To do so, one should install the kmail5 package and the akonadi-server package (other components of the PIM suite are also there, with the 5 suffix): this operation will uninstall the 4.14 packages (but not remove any local data) and install the new version of mail and PIM. To go back, install akonadi-runtime and the respective packages without the 5 suffix (e.g., kmail, korganizer).
It is essential for upstream KDE to have proper bug reports, in particular for PIM, so please report any issues you find. If instead you find a bug in the packaging, turn over to openSUSE’s Bugzilla.
-
Not all packages are available on openSUSE 13.2 due to the version of KF5 and extra-cmake-modules that is shipped there. ↩
Instalasi dan Konfigurasi Web Server
Pada kesempatan yang lain, penulis pernah mencoba menginstalasi web server menggunakan XAMPP versi Linux yang bisa diunduh di url https://www.apachefriends.org/. Setelah bermigrasi ke openSUSE Tumbleweed, penulis mencoba melakukan instalasi web server dengan metode yang sama. Akan tetapi pada proses instalasi tersebut, penulis gagal menjalankan servis MySQL dan FTPD. Walau mungkin solusinya bisa dicari, akan tetapi terlintas ide untuk menginstal web server dari repositori openSUSE itu sendiri. di langsir dari portal https://en.opensuse.org/SDB:LAMP_setup, untuk menginstal web server Anda perlu mengunduh beberapa aplikasi yang diperlukan, antara lain sebagai berikut.
- Apache2, buka terminal kemudian ketik sudo zypper in apache2. Untuk menjalankan servicenya, ketik diterminal (login sebagai root) systemctl start apache2.service
- PHP5, buka terminal kemudian ketik sudo zypper in php5 php5-mysql apache2-mod_php5
- MariaDB, buka terminal kemudian ketik sudo zypper in mariadb mariadb-tools. Untuk menjalankan servicenya, ketik (login sebagai root) systemctl start mysql.service
- Jika ingin menginstal phpMyAdmin ketik di terminal, sudo zypper in phpMyAdmin. Untuk mengaksesnya (misal lokal) ketik http://localhost/phpMyAdmin/.
Setelah service yang dibutuhkan dijalankan, sekarang untuk mengetesnya ketik di browser http://localhost/, jika hasilnya seperti gambar berikut, maka langkah pertama berhasil.

Sebelum melanjutkan ke langkah selanjutnya, mengenai proses instalasi web server juga bisa dilakukan melalui YaST, berikut langkah – langkahnya.
- Buka YaST – Software – Software Management
- Ubah pilihan filter menjadi Patterns
- Scrolldown pilihan ke bawah, ceklist group Web and Lamp Server
- Pilih paket yang akan diinstal, atau jika tidak mau repot openSUSE secara default sudah menceklist semua paket yang tersedia di group tersebut.
- Pilih Accept untuk menginstalnya, pastikan tersedia koneksi internet
Pada saat pengetesan melalui browser maka akan diperoleh keterangan Access forbidden!. Hal ini dikarenakan secara default openSUSE akan mengaktifkan folder yang memiliki file index.html. Untuk mengatasi permasalahan ini, Anda hanya perlu mengubah file default-server.conf yang terletak di direktori /etc/apache2. Ubah baris Option None menjadi Option All.
Folder utama dari web server terletak di /srv/www/htdocs, meski demikian Anda bisa mengubahnya ke direktori tertentu (misal diset ke direktori home). Caranya mengubah baris pada file yang sama (default-server.conf), pada baris DocumentRoot “/srv/www/htdocs” dan <Directory “/srv/www/htdocs”>, /srv/www/htdocs diganti sesuai direktori yang anda inginkan misal /home/muksidin/web. Setelah itu nyalakan ulang service servernya dengan mengetik systemctl restart apache2.service.
Setelah konfigurasi diatas selesai, namun index.php tidak bisa menampilkan halaman yang semestinya seperti pada gambar berikut.

Jalankan perintah a2enmod php5 di terminal dengan login sebagai root.

